nsdictionary取得指定key値
元の問題はCSDNクイズチャンネルから来ました。より多くの解決案をご覧ください。http://ask.csdn.net/questions/2265
問題の説明:
nsdictionaryにJson解析の結果を保存します。
ありがとうございます。
ソリューション:
ゲタの中には3つのNSDictionaryがあります。
問題の説明:
nsdictionaryにJson解析の結果を保存します。
{
"statusCode":"200",
"body":[
{
"status":"success",
"remarks":null
}
],
"data":[
"abcd":[
{
"category":"a",
"title":"b",
"id":"24"
},
{
"category":"c",
"title":"crd",
"id":"65"
},
{
"category":"ds",
"title":"sd",
"id":"18"
}
]
},
{
"efgh":[
{
"category":"ds",
"title":"sd",
"id":"18"
},
{
"category":"sd",
"title":"sd",
"id":"1"
}
]
},
{
"ijkl":[
{
"category":"ds",
"title":"sd",
"id":"18"
},
{
"category":"sd",
"title":"sd",
"id":"1"
}
]
}
]
}
キーワード@dataのデータは配列に保存できます。NSMutableArray *getdata=[[NSMutableArray alloc]init];
getcat=[results objectForKey:@"data"];
次に、最初の索引のvalues(category, title, id)
にはどうすればいいですか?例えば'abcd'ですかありがとうございます。
ソリューション:
ゲタの中には3つのNSDictionaryがあります。
{
"category":"a",
"title":"b",
"id":"24"
},
{
"category":"c",
"title":"crd",
"id":"65"
},
{
"category":"ds",
"title":"sd",
"id":"18"
}
最初の索引のvaluesに設定します。NSDictionary *firstDic = [getdata objectAtIndex:0];
[firstDic setValue:@"new category" forKey:@"category"];
[firstDic setValue:@"new title" forKey:@"title"];
[firstDic setValue:@"new id" forKey:@"id"];