你有一个JSONArray
文本。没有数组JSONObject
。
{ // Json object node
"text":[ // json array text
"Morate popuniti polje tekst." // value
]
}
只需使用
for (int i = 0; i < arrayJson.length(); i++) {
String value = arrayJson.get(i);
}
实际上不需要循环,因为 json 数组中只有 1 个元素
你可以使用
String value = (String) arrayJson.get(0); // index 0 . need to cast it to string
或者
String value = arrayJson.getString(0); // index 0
http://developer.android.com/reference/org/json/JSONArray.html
public Object get (int index)
Added in API level 1
Returns the value at index.
Throws
JSONException if this array has no value at index, or if that value is the null reference. This method returns normally if the value is JSONObject#NULL.
public boolean getBoolean (int index)
getString
public String getString (int index)
Added in API level 1
Returns the value at index if it exists, coercing it if necessary.
Throws
JSONException if no such value exists.