在将JSON对象转换为JSON数组时出现问题。

huangapple 未分类评论49阅读模式
英文:

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"
      }
   ]

}




huangapple
  • 本文由 发表于 2020年5月5日 20:59:00
  • 转载请务必保留本文链接:https://java.coder-hub.com/61613764.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定