xcode - iOS 5 JSON Parsing Results in Cocoa Error 3840 -
xcode - iOS 5 JSON Parsing Results in Cocoa Error 3840 -
i'm having hard time parsing below json string on ios 5.
{"states": [{"name": "arizona","cities": [{"name": "phoenix"}]},{"name": "california","cities": [{"name": "orange county"},{"name": "riverside"},{"name": "san diego"},{"name": "san francisco"}]},{"name": "nevada","cities": [{"name": "las vegas"}]}]}
and here's code:
- (void) parsejson { nserror *jsonerror = nil; nsdata *jsondata = [nsdata datawithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"locations-json" oftype:@"rtf"]]; if (jsondata) { nsdictionary *jsonobjects = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers error:&jsonerror]; if (jsonerror) { nslog(@"json error: %@", [jsonerror localizeddescription]); return; } nslog(@"%@", jsonobjects); } }
i maintain getting error:
json error: operation couldn’t completed. (cocoa error 3840.)
i'd appreciate help on because , incapable of fixing this.
one thing strikes me wrong this:
[[nsbundle mainbundle] pathforresource:@"locations-json" oftype:@"rtf"]
your info rtf file?? should txt
file (or other sort of plain text file). rtf files contain text formatting data, this:
{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470 {\fonttbl\f0\fswiss\fcharset0 helvetica;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww10800\viewh8400\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural \f0\fs24 \cf0 \{"states": [\{"name": "arizona","cities": [\{"name": "phoenix"\}]\},\{"name": "california","cities": [\{"name": "orange county"\},\{"name": "riverside"\},\{"name": "san diego"\},\{"name": "san francisco"\}]\},\{"name": "nevada","cities": [\{"name": "las vegas"\}]\}]\}}
when read that in info , seek parse json, 3840 error you're seeing. error's description says:
the info couldn’t read because has been corrupted. (no string key value in object around character 2.)
so looks me don't have json. have rtf data.
ios xcode json ios5.1
Comments
Post a Comment