问题描述
我想解析一个简单的JSON数组,如:
I want to parse a plain JSON array like:
{
"ns": [
[
"1364987475027",
"Alert1",
"001"
],
[
"1364987475042",
"Alert2",
"001"
],
[
"1364987475058",
"Alert4",
"001"
]
]
}
将数组放入简单的字符串数组中。我发现很多帖子都带有JSON字典数组。但在这种情况下,JSON没有值的键。
请帮忙。
To get the array in simple arrays of string. I found many posts with JSON dictionary arrays. But in this case the JSON is not having keys for the values.Kindly help.
推荐答案
答案: 。
NSJSONSerialization
类可用于将JSON转换为Foundation对象,将Foundation对象转换为JSON。在您的情况下,您应该使用 -JSONObjectWithData:options:
的 NSJSONSerialization
类来检索给定的Foundation对象JSON数据。
NSJSONSerialization
class can be used to convert JSON to Foundation objects and Foundation objects to JSON. In your case, you should use -JSONObjectWithData:options:error:
of NSJSONSerialization
class to retrieve a Foundation object from given JSON data.
示例代码:
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray *fetchedArr = [json objectForKey:@"ns"];
这篇关于在Objective C中解析Plain JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!