Search code examples
jsonobjective-c

Parsing JSON, key without quotes


I am getting a response from a server where the key is not within quotes. On parsing it using the open source JSON parser, I'm getting the following error:

-JSONValue failed. Error is: Unrecognised leading character

If I add double quotes (") to the key manually, I get what I want. What do I do?

Please see the following, if it's correct:


{
    status: 200,
    statusMsg: "Success",
    statusInfo: {
        custType: "Active",
        custCount: 600,
        custAccount: "Premium" 
    },
    custInfo: {
        custName: "ABC",
        custCode: "CU102",
        custNumber: 9281 
    },
    errors: [
        
    ]
}

Solution

  • I originally put this in as a comment, but I think it counts as an answer albeit not necessarily a very helpful one.

    The example you posted is not JSON. Check the JSON syntax. The only unquoted entities allowed except for numbers, objects and arrays are null, true, false. So the keys in your example are invalid and so are the non numeric values.

    So you really should raise a defect report with the service provider (if they are claiming that they are producing JSON, rather than some modified version of it).

    If they refuse to fix the problem, you'll need to write a nearly-JSON parser or find an existing one that is less strict about syntax.