JSON and User Entered Data

You must Login before you can answer or comment on any questions.

I am creating a JSON file on a server that is downloaded by my app which for the most part works perfectly. I am having lots of issues with parsing the JSON because of special characters in the user entered data.

Any suggestions?

Thanks,

David

2 Answers

How are you creating the JSON file on the server ? Most languages will have a way of 'escaping' the special characters so that they don't cause parsing problems. You could also try adding a \ before the characters in question.

— answered 7 months ago by John Comerford
answer permalink
2 Comments
  • I found a function called JSStringFormat which helped out. The issue I have now is very strange. My JSON object is about 5000 lines. It validates properly at http://jsonlint.com/ but it errors when I try to parse it in my app. Here is the weird part. If I open the file and save it in titanium studio, it parses fine after that... Once I rebuild the app, which downloads and replaces the JSON file, it will have parse errors again, until I open the file and save it.

    Ideas?

    — commented 7 months ago by David Jones

  • — commented 7 months ago by abcdefg sadfdsds

Sounds to me like there are some control characters still in your document. Is the program that is creating the file adding carriage returns ? Is the server linux ? At a guess I bet that the program that creates the files is adding a carriage return/line feed to the document. To put it into jsonlint you must be opening it in an editor and using copy/paste. I bet the editor is converting the carriage returns/line feed before you copy, as is Titanium studio when you save the file.

— answered 7 months ago by John Comerford
answer permalink
3 Comments
  • — commented 7 months ago by abcdefg sadfdsds

  • I have figured out exactly what field is causing the issue. It is a description field that is populated via text area on a website so there is no telling what type of characters the parser getting hung up on. I am querying the database for the value and then putting it into my JSON text file on the webserver which is downloaded by my app. I have 600 rows in this JSON text file and no way of knowing exactly what row and character is causing the issue. All I have to do to get it to work is to open and save the document. Can someone give me some guidance on what types of characters to search for?

    — commented 7 months ago by David Jones

  • Finally figure it out.. It was a right single quote ascii char 146. I dont understand why it was a problem but I found a string function for XML that converts the characters to HTML encoded versions and now it works fine.

    — commented 7 months ago by David Jones

Your Answer

Think you can help? Login to answer this question!