JSON text did not start with array or object and option to allow fragments not set

后端 未结 5 838
孤城傲影
孤城傲影 2020-12-04 01:50

I\'m sending this json response from server for a request to my IOS 7 app.

{
 \"root\": {
    \"success\": \"1\",
    \"message\": \"Successfully retrieved          


        
5条回答
  •  星月不相逢
    2020-12-04 02:12

    The JSON that you posted looks Ok. If that is what your iOS application received, it would get parsed. Even if it wasn't Ok, you wouldn't get this error message. JSON must start with '[' if it is an array, and '{' if it is a dictionary like yours, and everything else you get the error message that you got. So even if you sent '[934knsdf239][@@@' you wouldn't get this error message, because the data starts with the [ indicating an array.

    You need to debug this in the iOS application. First convert the data to a string and print that and check it. If the string looks alright then print the data itself - sometimes people manage to add 0 bytes or control characters, or two byte order markers or something similar which are invisible in the string but are not legal JSON.

    The option NSJSONReadingAllowFragments allows JSON that consists just of a string, number, boolean or null value. Don't use this unless you want to be able to process one of these on its own.

提交回复
热议问题