Talk:JSONObject

From Unify Community Wiki
Jump to: navigation, search

Am I right in saying that this class does not take into account escaped characters, like \" in strings? Ppeterson 15:56, 5 March 2011 (PST)

Yes and no

Yes, you are quite right... Or you were. I wish this wiki would forward comments to the e-mail of the contributor, because I had been meaning to come back and update this. I've made quite a few tweaks to this class since I submitted it, so I'll get the latest up today. I came across the escaping problem when returning JSON-formatted data including JSON data (wha??) which was itself a string with the quotes escaped. Needless to say the initial result was not desirable.

Also I added a block which strips newlines, tabs, etc. from the input strings so it can be fed a formatted string. Also, the escaping is taken care of: I added the following: <csharp> if(str[i] == '\\') { i++; continue; } </csharp> to the string loop. It iterates the counter and continues, skipping over the '\' and the following character. Let me know if this works for your purposes, as I wouldn't be surprised if certain input strings confuse it.

Carriage Returns

I added a line that strips carriage returns to the block that reads in formatted strings. It already handled "\\r", but not "\r".

support for spaces

hi, I was trying this class with a sample JSon Object from the google chart api documentation, that file has spaces (check sampledata.json in https://developers.google.com/chart/interactive/docs/php_example) those spaces make the parser fail. I added this line to skip them: line 106: case ' ': break;

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox