objective c - JSON parsing - best practice for converting -


I have a string variable that holds the string [1,2,3] . It is an array of integers I want to convert this string to an integer integer using JSON functions etc. What is the best way to accomplish this?

Thanks

The code looks like this for conversion

  NSString * input = @ "[1,2,3]"; NSError * error; NSDTA * Data = [Input Data Device Encoding: NSUTF 8 string encoding]; NSArray * Output = [NSJSONSerialization JSONObjectWithData: Data Option: 0 Error: & amp; Error]; If (output! = Zero) NSLog (@ "% @", output); Other NSLog (@ "% @", error);  

Note that the objects in the array will be NSNumber , with the values ​​you specify.

If you want to change the NSArray in the NSNumbers in a standard C array of int , then add the following

  int array [ Output.count]; Int index = 0; For (NSN umber * number in output) array [index ++] = [number intValue]; For (int i = 0; i  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -