3

I have following json structure:

{
    [{
        "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 with C#? I have try var results = JsonConvert.DeserializeObject<dynamic>(json) but the result is an error:

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

5
  • try this stackoverflow.com/a/16333468/4810628 Commented May 31, 2015 at 12:18
  • 2
    I'm not so sure this is valid JSON to being with; the outermost array should start with an identifier e.g { "things":[....]} Commented May 31, 2015 at 12:19
  • 2
    This is invalid JSON. Check jsonlint.com. You start with an object and right inside put an array without property name. Commented May 31, 2015 at 12:20
  • 2
    It's an array or a single object? Try without the first braces! Commented May 31, 2015 at 12:20
  • 1
    you can use below answer or you can remove outer curly braces { }. Commented May 31, 2015 at 12:36

2 Answers 2

3

Complementing the @Stephen awswer, you can yet use only the inner 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 issue seems to be your original json realy. =)

Sign up to request clarification or add additional context in comments.

Comments

3

The JSON posted doesn't 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
    }]
}

Note how the outermost array has now has an identifier which is required; that is to say your parsed object will have a things property which is an array of that inner structure.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.