I have the following JSON:
{"errors":[{"code":888,"errorId":"xxx","message":"String value expected","fields":["name", "address"]}, {}, {}]}
我希望能以以下方式获取“fields”:
public static String getField(json, errorsIndex, fieldIndex) {
JSONObject errorJson = json.getJSONArray("errors").getJSONObject(errorIndex);
String value = errorJson.[getTheListOfMyFields].get(fieldIndex);
return value;
}
但我找不到一种方法来实现这部分[getTheListOfMyFields]。有什么建议吗?
getTheListOfMyFields
应该是一个索引吗? - andrewdleachvalue
成为“fields”数组中索引为fieldIndex
的元素,是这样吗?例如,如果fieldIndex
为1,则value
将是“address”? - gla3dr