iphone - NSJSONSerialization JSONObjectWithData returns null if json object has some junk value -


i using following code snippet parse json object url.

   nsdata* data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:urladdress] options:nsdatareadinguncached error:&error];     if (error != nil) {         nslog(@"%@",[error localizeddescription]);             }   else {         nslog(@"no error: %@", data);  //looks here. console displays raw data      }      id result = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error];      if (error != nil) {         nslog(@"%@",[error localizeddescription]);         return nil;      }   else {         nslog(@"no error: %@", [result objectforkey:@"exams"]); //console displays value ("no error: value key...") unless degree symbol present in case displays no error: (null)      } 

i have 10 urladdresses,for 7 urls jsonobjectwithdata returns json object.for remaining 3 urls jsonobjectwithdata returns null.i tried opening urls in safari.i have seen junk characters in it.i suspect problem junk character.how solve issue?

i have seen "jsonobjectwithdata returns null if degree symbol in json object" link similar.suggested use unicode escape sequence.how use "unicode escape sequence" solve issue.

i agree, there encoding problem said.

referring rfc 4627, chapter 1, json string "[…]is sequence of 0 or more unicode characters […]". referring rfc 4627, chapter 3, "json text shall encoded in unicode. default encoding utf-8." get, no unicode. (please check first.)

you have several options handle that:

a) print out rfc 4627 on thick paper. go person, responsible sending out response , knock paper on head until says "i respect rfc 4627." (this 1 of rare cases, in violence is solution.)

b) if know used encoding, create string out of data , re-encode unicode. scan encoded data nsjsonserializer.

c) replace occurences of bad codes manually.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -