英文:
Trouble in converting JSON object to JSON Array
问题
我目前正在使用Json-simple jar文件,并且需要将我的JSON对象转换为JSON数组,我在许多地方看到要使用:
JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject) parse.parse(jsonString);
JSONArray arr = jsonObject.getJSONArray("users");
然而,getJSONArray()
方法无法被识别。它显示找不到符号。我已经导入了整个org.json
包,但不确定如何使用它。
我的JSON来自一个URL,格式如下:
{
"warnings": [
],
"users": [
{
"id": 12345678,
"username": "abc123",
"firstname": "ABC",
"lastname": "DEF",
"fullname": "ABC",
"email": "abc@gmail.com",
"department": "Autoz",
"idnumber": "1234",
"firstaccess": 2552,
"lastaccess": 4242,
"auth": "ldap",
"suspended": false,
"confirmed": true,
"lang": "en",
"theme": "",
"timezone": "99",
"mailformat": 1,
"description": "Software Engineer",
"descriptionformat": 1,
"city": "Lahore",
"profileimageurlsmall": "srwegwegdrz",
"profileimageurl": "rbdrrebhez"
}
]
}
英文:
I am currently using the Json-simple jar file and need to convert my json object into json array, I read on many places to use:
JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject) parse.parse(jsonString);
JSONArray arr = jsonObject.getJSONArray("users");
However the getJSONArray() method isn't being recognized. It says cannot find symbol. I have imported all of the org.json package but not sure how this works.
My JSON is coming from a url and is:
{
"warnings":[
],
"users":[
{
"id":12345678,
"username":"abc123",
"firstname":"ABC",
"lastname":"DEF",
"fullname":"ABC",
"email":"abc@gmail.com",
"department":"Autoz",
"idnumber":"1234",
"firstaccess":2552,
"lastaccess":4242,
"auth":"ldap",
"suspended":false,
"confirmed":true,
"lang":"en",
"theme":"",
"timezone":"99",
"mailformat":1,
"description":"Software Engineer",
"descriptionformat":1,
"city":"Lahore",
"profileimageurlsmall":"srwegwegdrz",
"profileimageurl":"rbdrrebhez"
}
]
}
专注分享java语言的经验与见解,让所有开发者获益!
评论