C # in json array

I have the following structure json

:

{
    [{
        "name": "2542",
        "type": "FOLDER",
        "size": 0,
        "time": 0,
        "items": [{
            "name": "10-1432927746000.ksf",
            "type": "FILE",
            "size": 225,
            "time": 1433019520,
            "items": null,
            "info": {
                "seller": 10,
                "count": 2
            }
        }],
        "info": null
    }]
}

      

how can i parse it using c #? I tried var results = JsonConvert.DeserializeObject<dynamic>(json)

, but the result is an error:

Invalid property identifier character: [. Path '', line 1, position 1.

+3


source to share


2 answers


In addition to @Stephen awswer, you can only use an internal array like in this sample .

[{
        "name": "2542",
        "type": "FOLDER",
        "size": 0,
        "time": 0,
        "items": [{
            "name": "10-1432927746000.ksf",
            "type": "FILE",
            "size": 225,
            "time": 1433019520,
            "items": null,
            "info": {
                "seller": 10,
                "count": 2
            }
        }],
        "info": null
    }]

      



Anyway, the problem seems to be your original json realy. =)

+3


source


The JSON posted is not lint , so I suspect this is the root of your problem.

However, this does:



{
    "things":[{
        "name": "2542",
        "type": "FOLDER",
        "size": 0,
        "time": 0,
        "items": [{
            "name": "10-1432927746000.ksf",
            "type": "FILE",
            "size": 225,
            "time": 1433019520,
            "items": null,
            "info": {
                "seller": 10,
                "count": 2
            }
        }],
        "info": null
    }]
}

      

Notice how the outermost array now has an identifier that is required ; that is, your parsed object will have a property things

that is an array of this internal structure.

+3


source







All Articles