in response, i am getting gas_cylinders
key as single array object
"gas_cylinders":["[{\"quantity\":\"2\",\"name\":\"Medium Blue\",\"price\":\"100.0\",\"total_price\":\"200.0\"},{\"quantity\":\"3\",\"name\":\"Green\",\"price\":\"100.0\",\"total_price\":\"300.0\"},{\"quantity\":\"1\",\"name\":\"Dark Green\",\"price\":\"100.0\",\"total_price\":\"100.0\"}]"]
Note:- tripDictionary
contain below data..
(lldb) po tripDictionary
{
"gas_cylinder_total" = 600;
"gas_cylinders" = (
"[{\"quantity\":\"2\",\"name\":\"Medium Blue\",\"price\":\"100.0\",\"total_price\":\"200.0\"},{\"quantity\":\"3\",\"name\":\"Green\",\"price\":\"100.0\",\"total_price\":\"300.0\"},{\"quantity\":\"1\",\"name\":\"Dark Green\",\"price\":\"100.0\",\"total_price\":\"100.0\"}]"
);
}
i am taking gas_cylinders
like below way..
NSArray *arr = [tripDictionary valueForKey:@"gas_cylinders"];
if (arr && arr.count > 0) {
NSLog(@"first obj = %@",arr[0]);
}
output of above NSLog
like..
first obj = [{"quantity":"2","name":"Medium Blue","price":"100.0","total_price":"200.0"},{"quantity":"3","name":"Green","price":"100.0","total_price":"300.0"},{"quantity":"1","name":"Dark Green","price":"100.0","total_price":"100.0"}]
how can i get this object in NSMutableArray
?
The data is not what you think it is. The value of the gas_cylinders
key is an array of JSON string.
NSArray *cylinders = tripDictionary[@"gas_cylinders"];
NSString *firstCylinder = cylinders[0];
At this point, firstCylinder
is a JSON string. You need to parse that JSON string to get the desired array of dictionaries contained in the JSON string.