objective c - Issue with parsing JSON data -
i trying convert string json object , unsure why not working. when nslog output told urldata not valid json serialization when looking @ string looks me valid json. have tried encoding utf8 still won't serialize. missing here? - note unnecessary code omitted post.
get request
urldata = [nsurlconnection sendsynchronousrequest:urlrequest returningresponse:&response error:&error]; nsdictionary *tempdict = [nsdictionary alloc];
parsing
if ([nsjsonserialization isvalidjsonobject:urldata] ) { nslog(@"is valid"); tempdict = [nsjsonserialization jsonobjectwithdata:urldata kniloptions error:&error]; } nslog(@"is not valid");
definition: isvalidjsonobject: returns boolean value indicates whether given object can converted json data.
as mentioning in question, isvalidjsonobject
returns boolean value indicates whether given object can converted to json data
in case, don't want create json data, instead create dictionary out of json data. :
tempdict = [nsjsonserialization jsonobjectwithdata:urldata options:nsjsonreadingmutablecontainers error:&error]; if (!tempdict) { nslog(@"error parsing json: %@", error); }
Comments
Post a Comment