开发者

Can't Fetch the json String Key?

开发者 https://www.devze.com 2023-04-12 21:32 出处:网络
Please refer the following JSON format. This is my JSON response from the server. I can get the { myArrayList : ... } by using the key RESPONSE But i can\'t get the id by using the key myArrayList. Pl

Please refer the following JSON format. This is my JSON response from the server. I can get the { myArrayList : ... } by using the key RESPONSE But i can't get the id by using the key myArrayList. Please help me find the solution.

{"RESPONSE":"{\"myArrayLis开发者_开发技巧t\":[{\"id\":1,\"title\":\"Ms.\",\"firstName\":\"jana\",\"middleName\":\"jana\",\"lastName\":\"jana\",\"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\":\"sugadev\",\"middleName\":\"sugadev\",\"lastName\":\"jeyamani\",\"emailId\":\"jsugadev22@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}]}"}


The key myArrayList would give you an array of dictionaries. Store it in an array. Then use objectAtIndex on that array to get individual dictionaries and then use the key "id" on each to fetch your value.


Your JSON string is not properly formatted.

Try this:

{"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}]}}


This is your 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
                    }
                ]"
            }

as you may see, you have some bad formating, i.e the 3rd quotation mark shouldn't be there, you have a quotationmark after the end-array-bracket, and there seems to be missing a } at the end..


Thanks to all,

I found the solution that i got the {"myArrayList"...} as a string thats the reason i can't get the rest of the keys properly

i Found by using this coding

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
}

And i took the result as per normal way by using webService developer

Thank you for you answers friends :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号