因此,我使用http post方法从API请求一些数据,然后收到一个JSON响应,然后看到类似于JSON响应的字符串,如下所示:将字符串中的数字转换为列表java
{"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"}]}
我想从这个列表中提取数字,或者更好地检查多少个数字在0.2-1.0之间,如果这个条件是真的,则增加一个整数值。
比如我想要做这样的事,但我只是找不到正确的语法我。
if(responseString.contains("0.0-0.2")
{
OccurencesNeutral++
}
if(responseString.contains("0.2-1.0")
{
OccurencesPositive++
}
哎克里斯 - 这似乎是正是我要找的,但我发现用线的JSONObject数据= results1.get(我)的错误;我对JSON相当陌生,因此为什么我将响应者直接更改为字符串 – user3456401
我更新了我的答案,现在能工作吗?我只是从脑海中写下来的,所以它可能有流浪语法错误... – BadIdeaException
它现在正在使用results1.get(i)行,但它看起来不像data.get(“score” )被宣布为双重? – user3456401