iOS 5 JSON Parsing Results in Cocoa Error 3840

One thing that strikes me as incorrect is this:

[[NSBundle mainBundle] pathForResource:@"Locations-JSON" ofType:@"rtf"]

Your data is an RTF file?? It should be a txt file (or any other sort of plain text file). RTF files usually contain text formatting data, like 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 I read that in as a data and try to parse it as JSON, I get the 3840 error you’re seeing. That error’s description says:

The data couldn’t be read because it has been corrupted. (No string key for value in object around character 2.)

So what it looks like to me is that you don’t actually have JSON. You have RTF data.

Leave a Comment