2

I have problem with getJSON and a multi-dimensional array. If I use one data:

{ "Id": "1", "Item1": 1, "Item2": "2", "Item3": "3"}

$.getJSON(geturl, function(data) {
    $('.Item' + data.Id).html(data.Item1);
}

It's working. But if I use a multi array result;

[
    { "Id": "1", "Item1": "1", "Item2": "2", "Item3": "3", },
    { "Id": "1", "Item1": "1", "Item2": "2", "Item3": "3", }
]

It doesn't work. Can anyone tell me why?

3

2 Answers 2

2

Your second JSON example is incorrectly formatted as it is missing an opening brace, has commas at the end of arrays and your 'array' value has no key. Try this:

[{
    "Array": {
        "Id": "1",
        "Item1": 1,
        "Item2": "2",
        "Item3": "3"
    },
    "Id": "1",
    "Item1": "1",
    "Item2": "2",
    "Item3": "3"
}]

You can use JSONLint to check the validity of your JSON.

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

2 Comments

@user1082554 why have you posted that link?
1

Check your json with http://www.jsonlint.com it is not in correct format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.