Get In Touch
This form does not yet contain any fields.

    « Reserving your iOS App Name | Main | Don't write down feature requests! »
    Monday
    Dec202010

    Parsing JSON in iOS the right way

    I thought I would share a little detail that burned me this week.  I'm working on a new project that integrates with Twitter to pull data down from the JSON Search API.  There are a ton of tutorials out there that describe how to use the JSON Framework to parse a JSON resultset with iOS, although one thing I noticed with all the tutorials, is that they are doing this Wrong! 

    A good example is the tutorial from IOS Developer Tips this is actually a really great tutorial for the most part, but there is one error, that leads to epic failure.

    The failure occurs with the usage of

    - (void)connection:(NSURLConnection *)connection 
    didReceiveData:(NSData *)data

    which is the method they are using to act on the JSON results. When I tried to implement this with the Twitter search api, it would sometimes work, and sometimes fail. It was completely random and driving me insane. I would receive these horrid errors from the JSON parser... 

    "Error Domain=org.brautaset.JSON.ErrorDomain Code=5 \ 
    "Unescaped control character '0x0'\"

    This is the worst kind of error because it works sometimes, and fails miserably in others and none of the debug output is really helpful at all.

    Now the reason why this fails is due to the nature of the Asynchronous request setup using NSURLConnection previously in this example.  This will result in the didReceiveData method *possibly* being called multiple times as the data is delivered.  Meaning sometimes I would get a whole JSON data string that the parser could parse fine, but sometimes I would end up attempting to parse the fragments of the JSON string that had been downloaded so far, thus resulting in failure.

    The right way to implement this is to create an NSMutableData object and when the didReceiveData method is called, append the result data to the NSMutableData object.  Then utilize the connectionDidFinish method of NSURLConnection, to parse the resulting and now complete dataset.

    Special thanks to  for the guidance on this one...

    References (144)

    References allow you to track sources for this article, as well as articles that were written in response to this article.
    • Response
      Response: yacon syrup buy
      How come my computer does not register the other computers in the network?
    • Response
      I opened up a blogspot website and when I closed it 15 or so new windows opened back up to the same site. Why did that happen? Was it a virus?. Will it hurt my computer? How do I find it and get rid of it? I am running 2 virus ...
    • Response
      Response: renters insurance
      How do you make your blog (on Blogspot) for invited members only?
    • Response
      Response: seovolución
      What is the best free blog for a photographer to use?
    • Response
      Response: seovolución
      How do you start building a WordPress site for an already existing website?
    • Response
      How do I copy my Wordpress blog onto my computer so I can locally edit and try out plugins before publishing?
    • Response
      Response: terry cloth robe
      I want to protect some of the original writing on my website & was wondering how to do this.... a)Can I put the Copyright notation on it without revealing my real name? . b)How do I have proof that it is my original work? How about saving the writing in MS ...
    • Response
      Response: insurance products
      How do you compute the start-up costs for starting a website?
    • Response
      What are the most effective Wordpress plugins to attract the most relevant traffic and maximize website sales?
    • Response
      I have been given a Dell computer from my sister. However, her former husband set up his account on this computer (says he cannot remember the password), making himself the only administrator. Now, I cannot add any programs ( like iTunes), nor can I delete anything. How can I clear his ...
    • Response
      I should add that I'm not that technical, so a solution that is easy to use would be more appropriate of the two. . . The website will work in a similar way to gumtree's classified ads. If this is possible would I also be able to add a charging mechanism ...
    • Response
      Response: optimize site
      click here for greatest seo australia work available
    • Response
      I'm looking for a nice digital camera under or around $200 for the purpose of blogging (as in wordpress, blogger, etc). I'm trying to get a blog which will be based around the daily photos I take despite the fact that I'm not really a photographer but only doing it for ...
    • Response
      I'm going to start a serious blog that will eventually hold a great deal of content. I am a graphic designer, and my husband does my web programming, so this is for reals (haha, yes I just said that). That being said, I've already started collecting my content and writing entries, ...
    • Response
      Response: agencia seo
      get greatest posicionamiento en buscadores anywhere
    • Response
      Is getting a Masters Degree in Creative Writing a waste of time?
    • Response
      I'm an aspiring writer-of all literary trades (journalism, screen writing, satire, etc)-but I want to start a blog for some adult oriented, romantic fantasy literature. Anyone know how I can start a blog that will allow me to do this? I believe I'll need a warning page before entrance, and I ...
    • Response
      see here for best dog medication available
    • Response
      I am new to web designing and it made me more confused when I stumble into this content-management-system thing. I'm planning to update a site that is not designed using JOOMLA and was wondering if I can use Joomla to update it..
    • Response
      Can I copyright 20 pages of old newspaper articles ?
    • Response
      click here for greatest info creator a forever recovery available
    • Response
      Response: rehab centers
      see here for greatest info forever recovery available
    • Response
      Response: Jeffrey W. Lynn
      Any suggestions on sites to start a blog where I can BS sports and another happenings?
    • Response
      Response: house market news
      I know its itself is free for personal file sharing....but people are also upload a content which is copyrighted....downloading this is illegal in uk or not? becoz we are not uploading like torrent only downloading.. Its anywhere illegal but people r still downloading in some countries like india, pak becoz the ...
    • Response
      Response: olympus properties
      Now, I'm a complete newbie (and dummie), so please help - I like a few features from Dynamic Drive, but how EXACTLY to insert them? Where do I go after I login into my Control Panel on Joomla?. I know how to copy-paste, but details? Please? I'm just afraid to delete ...
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Guy Hayenga
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Mdhuset
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: seoveinte info
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: weekend jobs
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: streaming debat
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: suarabakrie
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: hosting vps
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: hier
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: queen elsa costume
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: arassegaf.com
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: SwordAndScale
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: towing san jose
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Corey Park scam
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Corey Park scam
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Corey Park scam
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: blitz brigade hack
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jared Londry
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Phil St Ores
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: visit site
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jeff Halevy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Jared Londry
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Kion Kashefi
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Kion Kashefi
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Kion Kashefi
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: elder law attorney
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: micro sd cards
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: 64gb Micro SD
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: GoPro Mounts
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: judi bola online
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: 128gb Micro SD
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: download files
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: agen poker
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: u trust pharmacy
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: klasemenliga
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: GoPro Car Mount
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: pasarn bola
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: glorystarbet
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: surat dukungan
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Response: judi bola online
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: yuri manga
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Best electro house
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Get Forex Enigma
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
    • Response
      Response: PORNO
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Response: Viagra
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Response: pokerqiu
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Maduras
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: ww
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: kamagra zel
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: core de force
      first, almonds. core de force glucose was first co core de force nverted into energy. easily hurt http://www.coreforcebeachbody.com/ http://www.coreforcebeachbody.com/ the back muscles) lift (body lift " lumbar " don't leave the ground) tail can peppa pig ultimate collection 20 dvd set be slightly peppa pig ultimate collection 20 dvd set o ...
    • Response
      improve people's quality of life, 卷腹15次 core de force →仰卧举腿15次→平板30秒(动作间无休息, I'm not a fitness coach, then gradually increas core de force mma e the weight, In order to ensure their own behavior with the martial arts from the shot is four inch; exercise every morning martial arts ef http://www.coredeforcecoach.com/ f
    • Response
      Response: rappers in Phoenix
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: dunelm promo codes
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Raahe
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Response: adidas mma
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Suggested Website
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: toys
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Parsing JSON in iOS the right way - Blog - Remarkable Pixels
    • Response
      Response: Ayesha Navratil
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Response: airsoft
      Parsing JSON in iOS the right
    • Response
      Response: кислород
      Parsing JSON in iOS the right
    • Response
      Response: Lucius Wittner
      Remarkable pixels blog about iphone app development. traceroute traceroute pro babylogs looking glass
    • Response
      Parsing JSON in iOS the right
    • Response
      Response: vocational skills
      Parsing JSON in iOS the right
    • Response
      Parsing JSON in iOS the right
    • Response
      Response: Insert your Data
      Parsing JSON in iOS the right

    Reader Comments (1)

    http://sexoconabuelas.com/me-follo-madre-sexy.html

    June 30, 2016 | Unregistered Commentersexo gratis

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>