无法获取 json 字符串密钥?



请参考以下JSON格式。这是来自服务器的JSON响应。我可以用RESPONSE键得到{ myArrayList : ... }但是我不能用myArrayList键得到id。请帮我找出解决办法。

{"响应":"{"myArrayList ":[{ "id":1,"","女士。","firstName ": " jana ","middleName ": " jana ","lastName ": " jana ","emailId ":""," officalLandline ","43545346 ","移动":"34543534534 ","传真 ":""," skypeId ":""," gtalk ":""," windowsLive ":""," 脸谱网 ":""," linkedIn ":""," 网站 ":""," 讲话 ":""," contactSource ","外部参考","捐助 ": " 10月3日2011 12:00:00是","preferredTimeZone ": " GMT-11:00 ","lastEditedBy ": " admin ","组织 ":""," contactType ","零售商","shareAll ":null, "地位":null, "modeOfCommunication ":"移动","createdBy ": " admin ","createdTime ","10月11日,2011 11:21:00是","lastModifiedBy ":零},{ "id":2,"标题":"先生","firstName ","sugadev ","middleName ","sugadev ","lastName ","jeyamani ","emailId ","jsugadev22@gmail.com ","officalLandline ","34566744467 ","移动","2434234545 ","传真 ":""," skypeId ":""," gtalk ":""," windowsLive ":""," 脸谱网 ":""," linkedIn ":""," 网站 ":""," 讲话 ":""," contactSource ","伙伴引用","捐助 ": " 10月2日2011 12:00:00是","preferredTimeZone ":"萨摩亚群岛西部时间","lastEditedBy ": " admin ","组织 ":""," contactType ","零售商","shareAll ":null, "地位":null, "modeOfCommunication ":"移动","createdBy ": " admin ","createdTime ","10月11日上午2011 11:22:52 ","lastModifiedBy ":零}]}"}

键myArrayList会给你一个字典数组。将其存储在数组中。然后在该数组上使用objectAtIndex来获取单个字典,然后在每个字典上使用键"id"来获取您的值。

您的JSON字符串没有正确格式化。

试试这个:

{"RESPONSE":{"myArrayList":[{"id":1,"title":"Ms.","firstName":"safd","middleName":"afdsaf","lastName":"asfas","emailId":"","officalLandline":"43545346","mobile":"34543534534","fax":"","skypeId":"","gtalk":"","windowsLive":"","faceBook":"","linkedIn":"","website":"","remarks":"","contactSource":"External Reference","dob":"Oct 3, 2011 12:00:00 AM","preferredTimeZone":"GMT-11:00","lastEditedBy":"admin","organisation":"","contactType":"Retailer","shareAll":null,"status":null,"modeOfCommunication":"mobile","createdBy":"admin","createdTime":"Oct 11, 2011 11:21:00 AM","lastModifiedBy":null},{"id":2,"title":"Mr.","firstName":"asdf","middleName":"af","lastName":"fd","emailId":"sdfa@gmail.com","officalLandline":"34566744467","mobile":"2434234545","fax":"","skypeId":"","gtalk":"","windowsLive":"","faceBook":"","linkedIn":"","website":"","remarks":"","contactSource":"Partner Reference","dob":"Oct 2, 2011 12:00:00 AM","preferredTimeZone":"West Samoa Time","lastEditedBy":"admin","organisation":"","contactType":"Retailer","shareAll":null,"status":null,"modeOfCommunication":"mobile","createdBy":"admin","createdTime":"Oct 11, 2011 11:22:52 AM","lastModifiedBy":null}]}}

这是你的JSON:

{
  "RESPONSE":
    "{
        "myArrayList":[
            {
                "id":1,
                "title":"Ms.",
                "firstName":"safd",
                "middleName":"afdsaf",
                "lastName":"asfas",
                "emailId":"",
                "officalLandline":"43545346",
                "mobile":"34543534534",
                "fax":"",
                "skypeId":"",
                "gtalk":"",
                "windowsLive":"",
                "faceBook":"",
                "linkedIn":"",
                "website":"",
                "remarks":"",
                "contactSource":"External Reference",
                "dob":"Oct 3, 2011 12:00:00 AM",
                "preferredTimeZone":"GMT-11:00",
                "lastEditedBy":"admin",
                "organisation":"",
                "contactType":"Retailer",
                "shareAll":null,
                "status":null,
                "modeOfCommunication":"mobile",
                "createdBy":"admin",
                "createdTime":"Oct 11, 2011 11:21:00 AM",
                "lastModifiedBy":null
                },
                {
                    "id":2,
                    "title":"Mr.",
                    "firstName":"asdf",
                    "middleName":"af",
                    "lastName":"fd",
                    "emailId":"sdfa@gmail.com",
                    "officalLandline":"34566744467",
                    "mobile":"2434234545",
                    "fax":"",
                    "skypeId":"",
                    "gtalk":"",
                    "windowsLive":"",
                    "faceBook":"",
                    "linkedIn":"",
                    "website":"",
                    "remarks":"",
                    "contactSource":"Partner Reference",
                    "dob":"Oct 2, 2011 12:00:00 AM",
                    "preferredTimeZone":"West Samoa Time",
                    "lastEditedBy":"admin",
                    "organisation":"",
                    "contactType":"Retailer",
                    "shareAll":null,
                    "status":null,
                    "modeOfCommunication":"mobile",
                    "createdBy":"admin",
                    "createdTime":"Oct 11, 2011 11:22:52 AM",
                    "lastModifiedBy":null
                    }
                ]"
            }

你可能会看到,你有一些糟糕的格式,即第三个引号不应该在那里,你有一个引号后的结束数组括号,似乎有一个缺少的}在结束..

谢谢大家,

我找到了解决方案,我得到了{"myArrayList"...}作为一个字符串,这就是为什么我不能得到其余的键正确

i使用此编码找到

NSDictionary *responseDate = [response objectForKey:@"responseData"];
If ([[responseData objectForKey:@"results"] isKindOfClass [NSArray class]]) {
NSArray *resultsArray = [responseData objectForKey:@"results"];
   ... do other things to get to each result in the array ...
}
else if ([[responseData objectForKey:@"results"] isKindOfClass [NSDictionary class]]) {
 // it looks like each individual result in returned in a NSDictionary in your example
 ... do the things to handle the single result ...
} 
else {
 // handle no results returned
}

使用webService developer

将结果按正常方式取

谢谢你的回答朋友:)

最新更新