我如何使用 volley android 解析 json 对象内的 json 键值对
How do i parse json key value pairs inside a json object using volley andorid
我如何使用 Volley 解析它
{
"ref": "suc",
"contactInfo": {
"name": "Jezzi",
"age": "3",
"Place": "Kochi"
}
}
Android 中的代码
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String ref = jsonObject.getString("ref");
} catch (Exception e ) {
Log.i("Hello", e.toString);
}
}
我正在获取字符串值 ref,但我不知道如何获取其他值。
我认为这可能对您有所帮助:
try {
JSONObject jsonObject = new JSONObject(response);
String ref = jsonObject.getString("ref");
JSONObject contactJsonObject = jsonObject.getJSONObject("contactInfo");
String name = contactJsonObject.getString("name");
// and other values like this
} catch (Exception e ) {
Log.i("Hello", e.toString);
}
我如何使用 Volley 解析它
{
"ref": "suc",
"contactInfo": {
"name": "Jezzi",
"age": "3",
"Place": "Kochi"
}
}
Android 中的代码
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String ref = jsonObject.getString("ref");
} catch (Exception e ) {
Log.i("Hello", e.toString);
}
}
我正在获取字符串值 ref,但我不知道如何获取其他值。
我认为这可能对您有所帮助:
try {
JSONObject jsonObject = new JSONObject(response);
String ref = jsonObject.getString("ref");
JSONObject contactJsonObject = jsonObject.getJSONObject("contactInfo");
String name = contactJsonObject.getString("name");
// and other values like this
} catch (Exception e ) {
Log.i("Hello", e.toString);
}