phparraysjsonjsonlint

PHP's json_decode() with this JSON string


I have this JSON string:

 {
    "name": "test task1",
    "desc": "test desc1",
    "id": "1"
}{
    "name": "test task1aaaa",
    "desc": "test desc1",
    "id": "2"
}

But it looks like it's not correct (JSONLint tells me) so PHP's json_decode()can't decode it. There's any way to separate the two JSON arrays into two strings (or into how much string the arrays are) for making json_decode decode them?


Solution

  • Assuming your intention is to have an array of two elements, your JSON should look like:

    [
        {
            "name": "test task1",
            "desc": "test desc1",
            "id": "1"
        },{
            "name": "test task1aaaa",
            "desc": "test desc1",
            "id": "2"
        }
    ]