json - Numbers from a string into a list java -


so request data api using http post method , receive json response , have string looks json response, this:

{"status": "ok", "results": [{"score": 0.0, "id": "2"}, {"score": 1.0, "id": "3"}, {"score": 0.0, "id": "0"}, {"score": 0.0, "id": "1"}, {"score": 0.0, "id": "6"}, {"score": 0.23606, "id": "7"}, {"score": 0.0, "id": "4"}, {"score": -0.2295, "id": "5"}, {"score": 0.41086, "id": "8"}, {"score": 0.39129, "id": "9"}]} 

i want extract numbers list or better yet check how many numbers between 0.2-1.0 , if condition true increment integer value have.

for instance want cannot find right syntax me.

    if(responsestring.contains("0.0-0.2")     {     occurencesneutral++     }     if(responsestring.contains("0.2-1.0")     {     occurencespositive++     } 

when dealing json, should use jsonobject api. in case, should work:

try {     jsonobject json = new jsonobject(thestringyougot);     jsonarray results = json.getjsonarray("results");     (int = 0; < results.length(); i++) {         jsonobject data = results.getjsonobject(i);         double score = data.getdouble("score");     } } catch (jsonexception x) {     // handle exception... } 

in code, should replace hardcoded field names constants clean code.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -