Are TouchJSON returnable volatile objects?

I get json from web service. I am parsing this using the TouchJSON library. I save data for the user to change certain values, and then I want to return it to the web service.

The JSON object that I get contains the NSDictionary objects in the object, for example:

[ { "id": null, "created_at": 12332343, "object": { "name": "Some name", "age" : 30 }, "scope": "it stuff", "kind_id": 1, "valid": true, "refering_statement": { "id": 95 }, "user": { "id": 1 } } ] 

If I want to change the values ​​in this dictionary, I cannot, because the returned objects from TouchJSON are not changed.

Is there a way to return modified TouchJSON objects?

or is there a way that Objective-C creates an NSDictionary and all its children change?

or do I just need to go through each NSDictionary in an NSDictionary and copy all the data into a mutable copy and then re-paste everything?

Hope someone can help me with this :) Thanks in advance.

+4
source share
2 answers

TouchJson has the ability to return a mutable object, not a regular one. (I found it by looking at the source code.) By default, its "copy" is returned, not "mutablecopy".

 NSError *error = nil; jsonString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error]; NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding]; CJSONDeserializer *jsondeserializer = [CJSONDeserializer deserializer]; jsondeserializer.scanner.options = kJSONScannerOptions_MutableContainers; NSMutableDictionary *jsonitems = [[NSMutableDictionary alloc] initWithDictionary:[jsondeserializer deserializeAsDictionary:jsonData error:&error]]; 
+2
source

You can create a mutable dictionary from such a dictionary.

(assuming your JSS dictionary was named jsonDictionary)

 NSMutableDictionary *userDictionary = [NSMutableDictionary dictionaryWithDictionary:jsonDictionary]; 

Hope that solves it for you.

0
source

Source: https://habr.com/ru/post/1343027/


All Articles