에있는 NSDictionary에 중첩 된 JSON을 구문 분석 Json
중첩 :내가 가진 아이폰 OS
[
{
"result":"1",
"roleId":4
},
{
"projectInfo":[
{
"result":true
},
{
"Project":[
{
"ProjectId":5378,
"ProjectName":"ASAG",
"CountryId":146,
"ProjectGroupId":743,
"Description":"Axel Spinger AG"
},
{
"ProjectId":5402,
"ProjectName":"BIZ",
"CountryId":146,
"ProjectGroupId":759,
"Description":"Bizerba Win 7 BAU"
},
{
"ProjectId":5404,
"ProjectName":"BOM",
"CountryId":146,
"ProjectGroupId":743,
"Description":"Bombardier Transportation ThinApp Migration"
},
{
"ProjectId":5394,
"ProjectName":"REDBULL",
"CountryId":149,
"ProjectGroupId":762,
"Description":"Red Bull Mac Packaging"
},
{
"ProjectId":5397,
"ProjectName":"VHV",
"CountryId":146,
"ProjectGroupId":743,
"Description":"VHV Win7 Migration"
}
]
}
]
}
]
나는이 대답 같은 일부 특정 키 값을 얻기 위해 작은 조각으로 분리하는 것입니다 필요가있는 무엇 : How to parse JSON into Objective C - SBJSON
을 내 코드 :
SBJsonParser* jParser = [[SBJsonParser alloc] init];
NSDictionary* root = [jParser objectWithString:string];
NSDictionary* projectInfo = [root objectForKey:@"projectInfo"];
NSArray* projectList = [projectInfo objectForKey:@"Project"];
for (NSDictionary* project in projectList)
{
NSString *content = [project objectForKey:@"ProjectId"];
NSLog(@"%@", content);
}
그러나 루트 노드에서 projectInfo
을 얻으려고하면 오류가 발생합니다. 내 코드에 문제가 있습니까? 내 JSON
을 나눌 예제를 제공해주십시오. 어떤 도움이라도 좋을 것입니다.
무슨 오류가 발생 했습니까? – KerrM
어떤 오류가 있었습니까? 쓸 수 있어요? – saidozcan
오류는 루트 요소가 사전이라는 사실에 기인합니다. 실제로는 사전의 배열입니다. – Alladinian