NSJSONSerialization results in EXC_BAD_ACCESS

前端 未结 3 1777
予麋鹿
予麋鹿 2020-12-09 21:17

Currently I am writing an app (Target iOS 6, ARC enabled) that uses JSON for data transmission and Core Data for persistent storage. The JSON data is generated out of a MySQ

3条回答
  •  醉酒成梦
    2020-12-09 22:06

    I know this question has been answered but I think some beginners may have the same issue as me and be brought to this question.

    The EXC_BAD_ACCESS message was caused by malformed JSON. As I had accidentally used the same name for an Object which causes issues when converting the JSON into a dictionary.

    Annoyingly it didn't bring up a formatting error. Here is an example of the JSON that caused the issue:

    "levels" : {
        "level1": {
            ....
        },
        "level1": {
            ... << All objects should have different names. This should be called level2.
        },
        "level3": {
            ...
        }
    

    To fix the issue I had to ensure that all objects of the same level had different names.

提交回复
热议问题