[英]How to real value for int from json
In my project I have an int jsonobject
by 20 value.在我的项目中,我有一个 20 值的int jsonobject
。 To get the int
value I used this:为了获得int
值,我使用了这个:
model.setInt(jsonObject.getInt("price"));
Now it returns 0 value for price.现在它返回 0 值的价格。 How can I get real value?我怎样才能获得真正的价值?
Here is My out put Json:这是我的输出 Json:
"data": [
{
"id": "571dd7817f8b9a1c190bbdb5",
"goods": 0,
"rate": {
"r1": 0
},
"price": 20
}
Please look at the example:请看例子:
String jsonData = "{\"count\": 20}";
JSONObject obj = new JSONObject(jsonData);
System.out.println("Count: " + obj.getInt("count"));
Your JSON
is invalid.您的JSON
无效。 you can use online tools like the jsonformatter to test the validity of your JSON
.您可以使用jsonformatter等在线工具来测试JSON
的有效性。
Maybe try something like:也许尝试这样的事情:
{
"data": [
{
"id": "571dd7817f8b9a1c190bbdb5",
"goods": 0,
"rate": {"r1": 0},
"price": 20
}
]
}
Looking at your code, you may have better luck with this structure:看看你的代码,你可能对这个结构有更好的运气:
{
"id": "571dd7817f8b9a1c190bbdb5",
"goods": 0,
"rate": {"r1": 0},
"price": 20
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.