XHR POST, JSON Array and a Tableview
This might be fairly easy for some, but I've been pulling my hair out over this the last 2 days.
I'm doing a post with the httpclient, which returns a response (this.responseText) as a JSON Array. I need to parse this array and populate a tableview with its data.
Here is the return data I'm getting
({"success":"true","results":[{"0":"Operation5","clan":"Operation5","1":"1","rank":"1","2":"6669","kills":"6669","3":"3","death":"3"}]})
I've tried looking through a lot of the JSON issues people have had on here, as well as looking through the kitchen sink examples. None of them seem to do the trick.
Im currently testing in Android 2.1, with the Titanium 1.4 SDK
Any examples, advice or code snippets you guys can share?
3 Answers
-
Accepted Answer
The response text contains "()" ? this makes it an invalid JSON string, try to remove it from the string and parse the result with JSON.parse
{"success":"true","results":[{"0":"Operation5","clan":"Operation5","1":"1","rank":"1","2":"6669","kills":"6669","3":"3","death":"3"}]}
so without parenthesis.
-
It would be a good idea to post what platform you are using, and a sample of the data return. Otherwise, you aren't likely to get much helps with post like this.
-
Ran on 2.1 android.
var b = JSON.parse('{"success":"true","results":[{"0":"Operation5","clan":"Operation5","1":"1","rank":"1","2":"6669","kills":"6669","3":"3","death":"3"}]}'); Ti.API.info(b.success); Ti.API.info(b.results[0].clan); Ti.API.info(b.results[0].rank); Ti.API.info(b.results[0].kills);