Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
"{\"item a \",\"item b  \",\"item c \"}"


What I have tried:

I want to deserialize the above JSON data into the list ( List
Posted
Updated 1-Feb-22 10:28am
v2

Quote:
JSON
{ "item a", "item b", "item c" }
That is not valid JSON. You will not be able to parse it using any JSON library.

A JSON array would use [ and ]:
JSON
[ "item a", "item b", "item c" ]
Since it's wrapped in { and }, it should be an object literal instead. However, object literals require values for their properties:
JSON
{ "item a": "some value", "item b": 42, "item c": false }
An object literal with property names without values is not valid JSON.

See the JSON specification[^] for more details.
 
Share this answer
 
You can't - that isn't valid JSON data.
JSON looks like this:
{
  "contacts": [
    {
      "id": 7113,
      "name": "James Norris",
      "birthDate": "1977-05-13T00:00:00",
      "phone": "488-555-1212",
      "address": {
        "postalCode": "92115",
        "street": "4627 Sunset Ave",
        "city": "San Diego",
        "state": "CA"
      }
    },
    {
      "id": 7114,
      "name": "Mary Lamb",
      "birthDate": "1974-10-21T00:00:00",
      "phone": "337-555-1212",
      "address": {
        "postalCode": "49245",
        "street": "1111 Industrial Way",
        "city": "Dallas",
        "state": "TX"
      }
    },
    {
      "id": 7115,
      "name": "Robert Shoemaker",
      "birthDate": "1968-02-08T00:00:00",
      "phone": "643-555-1212",
      "address": null
    }
  ]
}
And your's isn't - it's just a collection of strings.
A list would look more like this:
{MyItems:[{item:"item a"},{item: "item b"},{item:"item c"}]}
And give C# classes like this:
C#
public class MyItem
{
    public string item { get; set; }
}

public class Root
{
    public List<MyItem> MyItems { get; set; }
}
 
Share this answer
 
THis article will cover this topic in detail for you: Working with JSON in C# & VB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900