好吧,完全是 Android Studio 的新手,但我一直在尝试在 Android Studio 中解析 backpack.tf 的 json,但我有点卡住了。
这是我尝试解析的一小段 json:
{
"response": {
"success": 1,
"current_time": 1448658000,
"items": {
"A Color Similar to Slate": {
"last_updated": 1448654419,
"quantity": 48,
"value": 99
},
我用来解析 JSON 的代码在这里:
String finalJSON = buffer.toString();
JSONObject parentObject = new JSONObject(finalJSON);
JSONArray parentArray = parentObject.getJSONArray("A Color Similar to Slate");
JSONObject finalObject = parentArray.getJSONObject(3);
int price = finalObject.getInt("value");
return "$" + price;
非常感谢!
最佳答案
试试这个:
你有 JSON:
{"response":{
"success": 1,
"current_time": 1448658000,
"items": {
"A Color Similar to Slate": {
"last_updated": 1448654419,
"quantity": 48,
"value": 99
},
}
}
}
代码:
String finalJSON =buffer.toString();;
JSONObject parentObject = null;
try {
parentObject = new JSONObject(finalJSON);
JSONObject objectA_Color=parentObject.getJSONObject("response").getJSONObject("items").getJSONObject("A Color Similar to Slate");
int value=objectA_Color.getInt("value");
} catch (JSONException e) {
e.printStackTrace();
}
关于java - 在 Android Studio 中正确解析 JSON?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34487008/