Gson获取json字符串中key对应的值
字符串 :
//得到服务器返回的具体内容
1 | final String res = response.body().string(); |
例1:{"code":100,"msg":"处理成功!","extend":{"jsonString":{"userId":1,"userName":"123","userPwd":"123"}}}
1 | jsonObject = (JsonObject) new JsonParser().parse(res).getAsJsonObject(); |
例2:{"code":100,"msg":"处理成功!","extend":{"jsonString":[{"userId":1,"userName":"123","userPwd":"123"}]}}
1 | jsonObject = (JsonObject) new JsonParser().parse(res).getAsJsonObject(); |