【发布时间】:2019-05-15 23:29:46
【问题描述】:
我正在尝试解析 json 响应,以便我可以从对象中获取元素,出现以下错误 A JSONObject 文本必须以 '{' at 1 [character 2 line 1] 开始
public static String parseJsonResponse(String json){
String uId ="";
try {
JSONObject jsonObj = new JSONObject(json);
// String fname = jsonObj.getString("fname");
//String lname = jsonObj.getString("lname");
String aId = jsonObj.getString("id");
uId = aId;
} catch (Exception e) {
e.printStackTrace();
}
return uId;
}
这是使用邮递员的 json 响应,您会注意到没有标题
[
{
"id": "emplo000000000043567",
"displayName": "Tester, user1",
},
{
"id": "emplo000000000035386",
"displayName": "Tester, User2",
}
]
【问题讨论】:
-
那不是 JSON 对象。这是一个 JSON 数组。