Any Method to remove comment characters from JSON response in XCode?

I am new to JSON. Are there any methods in JSON parser to remove the comment characters from a response.

Eg. //{"response":"success".......

its SBJson for iPhone. from http://code.google.com/p/json-framework

-------------Problems Reply------------

The JSON grammar doesn't allow comments. That doesn't answer your question obviously, but I suspect you'll have to do some string manipulation and replace all those comment characters with empty strings and parse it with the JSON library only after doing so.

Can you post some more code? What part of the JSON string do you need?

Just don't parse the response into your dictionary/object/whatever...

The JSON parsers are very finicky about what is at the start of a JSON block to parse - they DO NOT like characters other than "{" at the start (at least that's what I found with TouchJSON, and it sounds like your case with SBJson is similar).

So just take your string and eliminate any characters before the opening "{", then you can parse:

NSRange startJSONRange = [myJSONString rangeOfString:@"{"];
startJSONRange.length = myJSONString.length - startJSONRange.location;
NSString *correctJSONString = [myJSONString substringWithRange:startJSONRange];

// parse correctJSONString

That will work, but the REAL fix is to tell whoever is sending you JSON to cut out the nonsense and send real JSON.

Category:iphone Views:2 Time:2010-01-28

Related post

  • PHP removes backslash characters from JSON 2011-04-11

    PHP removes all backslash characters from JSON when saving it to DB. I don'y correctly identified the problem. How to get rid off this problem? I want to save the JSON as it provided to PHP? --------------Solutions------------- Are you sure it's PHP

  • Remove accents from a JSON response 2010-04-29

    I get back a JSON response from a social networks site. There are certain accented characters that I would like to be removed. An example is : L\u00e1szl\u00f3 M\u00e1rton, that reads "László Márton" and I would like to be transformed into Laszlo Mar

  • Illegal characters in JSON response 2012-04-04

    I have a Sencha Touch app. One of the stores I have uses an ajax proxy and a json reader. Some of the strings in the JSON returned from my sinatra app occasionally contain this character: http://www.fileformat.info/info/unicode/char/2028/index.htm Al

  • Is there a method for removing whitespace characters from a string? 2011-09-12

    Is there a string class member function (or something else) for removing all spaces from a string? Something like Python's str.strip() ? --------------Solutions------------- You could simply do: myString = myString.Replace(" ", ""); If you want to re

  • Comment blocks around JSON responses 2009-06-19

    I've noticed that some web applications return AJAX responses with JSON data embedded within a comment block. For example, this would be a sample response: /*{ "firstName": "John", "lastName": "Smith", "address": { "streetAddress": "21 2nd Street", "

  • iPhone, special characters in JSON Response 2009-09-24

    Writing an iphone app, and I'm getting my data from a REST API that returns JSON. My problem is, some of the data has special characters embedded and Im getting errors. Example: MartÌn Petite-RiviËre-Saint-FranÁois Here is my current code: NSString *

  • How to remove string from the json response 2014-03-12

    I'm receiving a response like this: /*-secure-{"errors":["Runtime: Adapter 'DemoAdapter' does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/ But I only want the JSON data from the response. Like this: { "errors": ["Runtime: Adapter 'Demo

  • Box characters within JSON response 2010-06-22

    This is my JSON String which is generated using Java: [{\"userFirstNm\":\"Tamás\",\"userAsscId\":\"37732\",\"userLastNm\":\"Török\",\"userLanId\":\"a37732\"}] Using an alert in JavaScript displays boxes inside string and breaks my eval function. Plea

  • osx: remove all characters from string that cannot be used for a filenames in osx 2012-02-15

    Is there some standard method to remove all characters from string that cannot be used for a filenames in osx? Does the characters you are allowed to use correspond to some commonly used category? (I know defining a list of allowed characters would b

  • Grails file upload json response 2012-04-13

    I'm trying to upload a file in grails and then process a json response that is returned from the upload, but I'm not having much success. My view looks like: <script type="text/javascript"> function addData(e) { alert('adding data'); } </scr

  • Which method to use to remove string characters in stringBuilder class 2010-11-06

    I would to know, Is there any method in StringBuilder class in C#, which can remove string characters without changing other character of same value within different index? Like for a string like "5002", what if want to remove character in first inde

  • Remove unicode characters from textfiles - sed , other bash/shell methods 2011-12-19

    How do I remove unicode characters from a bunch of text files on the terminal? I've tried this but it didn't work: sed 'g/\u'U+200E'//' -i *.txt I need to remove these unicodes from the textfiles U+0091 - sort of weird "control" space U+0092 - same s

  • Removing specified characters from a string - Efficient methods (time and space complexity) 2012-01-12

    Here is the problem: Remove specified characters from a given string. Input: The string is "Hello World!" and characters to be deleted are "lor" Output: "He Wd!" Solving this involves two sub-parts: Determining if the given character is to be deleted

  • a C++ program to remove comments 2009-06-21

    I'm trying to create a program that takes a text file of c++ code and outputs another file with that code, minus any comments that it contains. Assuming that rFile and wFile are defined as follows: ifstream rFile; // File stream object for read only

  • Remove control characters from php String 2009-09-30

    seems trivial but give me a hard time: Does anyone have a hint for me on how to remove control characters like STX from a php string. I played around with preg_replace("/[^a-zA-Z0-9 .\-_;!:?äÄöÖüÜß<>='\"]/","",$pString) but found that it remove

  • How do I remove duplicate characters and keep the unique one only in Perl? 2010-04-06

    How do I remove duplicate characters and keep the unique one only. For example, my input is: EFUAHUU UUUEUUUUH UJUJHHACDEFUCU Expected output is: EFUAH UEH UJHACDEF I came across perl -pe's/$1//g while/(.).*\/' which is wonderful but it is removing e

  • How to remove special characters and letters from a line read from a text file in Python? 2010-07-14

    How can I remove special characters and letters from a line read from a text file while preserving the whitespaces? Let's say we have the following contents in a file: 16 ` C38# 26535 2010 4 14 2 7 7 3 8^@1 2 15 100 140 30 $ 14^] (2003 2 ! -6 �021 0

  • Velocity - Correct Regex to remove control characters? 2011-11-24

    I'm trying to remove undesirable characters from a string in Velocity (newlines are ok, but not things like EM and CAN ASCII control characters). #set($cleanScreen = $cleanScreen.replaceAll("\p{Cc}", "")) Throws: org.apache.velocity.exception.ParseEr

  • VB.NET: Manipulating TextBox Input: Dash every 5 characters and removing special characters 2011-12-21

    Essentially I am trying to replicate the Windows 7 (In-Windows) activation key TextBox form. The Form where it will auto capitalize letters, remove or deny all non alphanumeric characters except dashes every 5 characters that will be auto-input. I as

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.218 (s). 11 q(s)