I have an issue with json parsing
-I established a connection to a remote server to receive a json object, which looks like this
2011-08-31 13:23:27.280 WallpaperBackground[731:40b] jsonString:{"photoset":{"id":"72157627554107638", "primary":"6095921496", "owner":"66801517@N05", "ownername":"Gariya1", "photo":[{"id":"6096223569", "secret":"47081ffe65", "server":"6202", "farm":7, "title":"snakc", "isprimary":"0"}, {"id":"6095921496", "secret":"ea3b2b5076", "server":"6064", "farm":7, "title":"images", "isprimary":"1"},
-In the didReceiveData method, I assigned the json string
code:
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
then I built my dictionary
code:
NSDictionary *results = [jsonString JSONValue];
when i am runing this, In console i am getting these error
2011-08-31 13:23:27.284 WallpaperBackground[731:40b] -JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \"Unescaped control character '0x0'\" UserInfo=0x4e1d670 {NSLocalizedDescription=Unescaped control character '0x0'}",
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: server\" UserInfo=0x4e1d7c0 {NSUnderlyingError=0x4e1d6d0 \"Unescaped control character '0x0'\", NSLocalizedDescription=Object value expected for key: server}",
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Expected value while parsing array\" UserInfo=0x4e1d810 {NSUnderlyingError=0x4e1d7a0 \"Object value expected for key: server\", NSLocalizedDescription=Expected value while parsing array}",
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: photo\" UserInfo=0x4e1d8d0 {NSUnderlyingError=0x4e1d890 \"Expected value while parsing array\", NSLocalizedDescription=Object value expected for key: photo}",
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key: photoset\" UserInfo=0x4e1d980 {NSUnderlyingError=0x4e1d8b0 \"Object value expected for key: photo\", NSLocalizedDescription=Object value expected for key: photoset}"
If any one knw let me help out pl… thanx
Instantiate a
NSMutableData, preferably public in your interface definition found in your.hfile.Every time
connection:didReceiveData:is called, use theNSMutableData's "appendData:data"method to add the newly received data to the variable.When your
connection:didFinishLoading:method is called, you will have a completely filledNSMutableDataobject waiting to be parsed.Then call the
SBJSONParser'smethod to parse it like you did.EDIT
You declare a
NSMutableDataobject in your .h file.Whenever your connection object calls its delegate method
DidReceiveDatayou will append the data as follows:When the data is completely downloaded you will be left an object with your complete data in it.
So then in your finishedLoading method:
If you know for sure what the resulting datatype will be you can change the datatype of the results variable from id to i.e. NSDictionary, or NSArray.
Hope this helps.