获取对象为singleArrayObject,如何在NSMutableArray中转换?
Getting object as singleArrayObject, how to convert in NSMutableArray?
作为响应,我将 gas_cylinders
键作为单个数组对象
"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\"}]"]
注:- tripDictionary
包含以下数据..
(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\"}]"
);
}
我正在采取 gas_cylinders
如下方式..
NSArray *arr = [tripDictionary valueForKey:@"gas_cylinders"];
if (arr && arr.count > 0) {
NSLog(@"first obj = %@",arr[0]);
}
上面NSLog
的输出像..
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"}]
如何在 NSMutableArray
中获取此对象?
数据不是你想的那样。 gas_cylinders
键的值是一个 JSON 字符串数组。
NSArray *cylinders = tripDictionary[@"gas_cylinders"];
NSString *firstCylinder = cylinders[0];
此时,firstCylinder
是一个JSON字符串。您需要解析 JSON 字符串以获取包含在 JSON 字符串中的所需字典数组。
作为响应,我将 gas_cylinders
键作为单个数组对象
"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\"}]"]
注:- tripDictionary
包含以下数据..
(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\"}]"
);
}
我正在采取 gas_cylinders
如下方式..
NSArray *arr = [tripDictionary valueForKey:@"gas_cylinders"];
if (arr && arr.count > 0) {
NSLog(@"first obj = %@",arr[0]);
}
上面NSLog
的输出像..
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"}]
如何在 NSMutableArray
中获取此对象?
数据不是你想的那样。 gas_cylinders
键的值是一个 JSON 字符串数组。
NSArray *cylinders = tripDictionary[@"gas_cylinders"];
NSString *firstCylinder = cylinders[0];
此时,firstCylinder
是一个JSON字符串。您需要解析 JSON 字符串以获取包含在 JSON 字符串中的所需字典数组。