问题描述
我正在寻找一种在JSONArray的特定索引上调用get()
后仅返回值的方法.
I'm looking for a way to return only the value after a call to get()
on a particular index of a JSONArray.
这是我正在使用的方法:
Here'd the method I'm working with:
private void parseMessageRedrawBoard(String message) throws Exception {
Log.d("0000: ", message);
String trimmed = message.substring(message.indexOf("["));
Log.d("1111: ", trimmed);
JSONArray jsonArray = new JSONArray(trimmed);
//"column 0"
JSONObject subObject = jsonArray.getJSONObject(4);
JSONArray result = subObject.getJSONArray("row 4");
Log.d("YES: ", result.opt(0).toString());
}
但这又给了我这个{"column 0":"WhitePawn"}
我一直在寻找一种只能返回WhitePawn
的方法的文档,并且在JSONArray
上尝试了所有合理的查找方法后,似乎没有.
I've been looking at the docs for a method that would return me only WhitePawn
, and after trying all of the reasonable looking methods on JSONArray
it seems it doesn't have one.
只返回WhitePawn
而又不返回{"column 0":"WhitePawn"}
的惯用Java方法是什么?
What's the idiomatic java way to return only WhitePawn
, without also {"column 0":"WhitePawn"}
?
推荐答案
可以使用getJsonString()
仅返回特定键的值.
May you can use getJsonString()
to return only the value of specific key.
getJsonString(int index)
这篇关于在Java中仅从JSONArray获取值,即没有键也没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!