In iOS, how do I parse a JSON string into an object

前端 未结 7 840
日久生厌
日久生厌 2021-02-08 05:41

I come from Android dev, so sorry if I\'m missing obvious iOS concepts here.

I have a JSON feed that looks like:

{\"directory\":[{\"id\":0,\"fName\":\"...\

7条回答
  •  逝去的感伤
    2021-02-08 06:16

    Use: NSJSONSerialization

    You use the NSJSONSerialization class to convert JSON to Foundation objects and convert Foundation objects to JSON.

    An object that may be converted to JSON must have the following properties:
    
    The top level object is an NSArray or NSDictionary.
    All objects are instances of NSString, NSNumber, NSArray, NSDictionary, or NSNull.
    All dictionary keys are instances of NSString.
    Numbers are not NaN or infinity.
    

    You will get NSDictionary then you can parse (create) it to your object and then use it in CoreData.

提交回复
热议问题