有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    我建议使用json-lib将JSON序列化为Java对象

    然后可以从该对象获取JSONArray,并在其自己的数组中对其进行排序

    示例:

    JSONObject json = new JSONObject(jsonString);
    JSONArray owners = (JSONArray) json.get("owners");
    
    Iterator<String> iterator = owners.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next());
    }
    

    输出:

    Wr3pWSGt54GlRiEL
    XJU7ZqZ3MYrQncIw
    

    格式化JSON:

    {
       "_id":"XJTt3mXTOZpvgmOc",
       "cover_picture":"http://images.soundrop.fm/spaces/XJTt3mXTOZpvgmOg/5I3f6HGSSob6c1TTzK8vHg",
       "creator":"Wr3pWSGt54GlRiEL",
       "description":"Radio for Okicraft minecraft server!\nwww.okicraft.com",
       "display_name":"Molly's Bang'n Tunes FM AKA Okicraft Radio :D",
       "display_picture":"http://images.soundrop.fm/spaces/XJTt3mXTOZpvgmOg/AiTQDQBYGg1wesnhFVLao",
       "owners":[
          "Wr3pWSGt54GlRiEL",
          "XJU7ZqZ3MYrQncIw"
       ],
       "parameters":{
          "soundrop:chat":{
             "version":2
          },
          "soundrop:membership":{
             "version":2
          },
          "soundrop:playlist":{
             "version":2,
             "mode":"open"
          }
       },
       "presence":{
          "soundrop:chat":{
    
          },
          "soundrop:membership":{
             "members_live_count":0,
             "members_total_count":189,
             "members_max_count":8,
             "members_max_date":"2014-02-01T19:33:29Z",
             "members_summary":[
    
             ]
          },
          "soundrop:playlist":{
             "current":{
                "_id":"WPg2zdgdMsBxsge7",
                "title":"Son Of A Preacher Man",
                "artists":[
                   {
                      "_id":"WgCuwalktE9Wl4bS",
                      "display_name":"Dusty Springfield"
                   }
                ],
                "sources":[
                   {
                      "album":"At Her Very Best",
                      "length":144241,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:02hv6aR5wa2Vhw4Xo8DaN2",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM"
                      ]
                   },
                   {
                      "album":"Dusty In Memphis",
                      "length":149365,
                      "uris":[
                         "deezer:track:1104538",
                         "isrc:GBF086800754",
                         "isrc:USAT20702465",
                         "spotify:track:1IYeYU3r8CkP9ECrhdX9en",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:26EuE0OC3dbqcpIyIvS13O",
                         "spotify:track:28jBolSSfkXDYYOZWTcHDE",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:4UCIi4gRVUG7x4nFGQiKmo",
                         "spotify:track:5TbLONSGZsR8cbhNEodCH6"
                      ]
                   },
                   {
                      "album":"The Silver Collection",
                      "length":147823,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:0kHzYqfLwnfObM1v4E6LGI",
                         "spotify:track:0scrtPmtlIVwwk9s4LXJ8n",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:4UCIi4gRVUG7x4nFGQiKmo"
                      ]
                   },
                   {
                      "album":"Dusty In Memphis [Deluxe Edition]",
                      "length":149365,
                      "uris":[
                         "isrc:USAT20702465",
                         "spotify:track:7odHgoLFi3GQ90E9PeraI3"
                      ]
                   },
                   {
                      "album":"PULP FICTION Collector's Edition",
                      "length":146620,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:1rojMZ3XzgmAZhc5PpVDec",
                         "spotify:track:3iDaK0Vsw1jRfuGjGBVU25",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:43MOKEiRYA05XEGnjnkMgS",
                         "spotify:track:55iXg89f5nRwBeFI39FX1p"
                      ]
                   },
                   {
                      "album":"Drivetime",
                      "length":144895,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:1rojMZ3XzgmAZhc5PpVDec",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:4b3YH93d0kEJ5lVvFtkiLP"
                      ]
                   },
                   {
                      "album":"110% Oldies",
                      "length":145391,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:0kDT8dYWwdvuwfApPSU3TP",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:3EqAYYYyhCYWebfA06CRBg",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM"
                      ]
                   },
                   {
                      "album":"Dusty Springfield Hit Pac - 5 Series",
                      "length":144215,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:24IavnnaGG2AGYMdAwmVdn",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM"
                      ]
                   },
                   {
                      "album":"Movies",
                      "length":143953,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:4gYl9m2oErJgwY2cu2TsuB",
                         "spotify:track:79awzAL3IzFfvo60KvAuIC"
                      ]
                   },
                   {
                      "album":"Just Sing",
                      "length":146000,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:1pWd0ar7Y77ex8fWfaAyiq",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:4gYl9m2oErJgwY2cu2TsuB",
                         "spotify:track:65QTLn5NbBvLkR1U9aaHLA"
                      ]
                   },
                   {
                      "album":"100 Essential Hits - Woman",
                      "length":144000,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:2QLTd3D6Cb79rbPMMxVkRo",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:55iXg89f5nRwBeFI39FX1p",
                         "spotify:track:7B4UpODwurpp47tbnpsRSb"
                      ]
                   },
                   {
                      "album":"True Drivetime (3 CD Set )",
                      "length":145000,
                      "uris":[
                         "deezer:track:910223",
                         "isrc:GBF086800754"
                      ]
                   },
                   {
                      "album":"100 Soul",
                      "length":146000,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:09crwvurlODl7CYY7Tv1Ku",
                         "spotify:track:25jzJ7xqVTMsG4DAR50W48"
                      ]
                   },
                   {
                      "album":"Just Dusty",
                      "length":145000,
                      "uris":[
                         "isrc:GBF086800754",
                         "spotify:track:0knTTHUdnVn5CSblhcw7bS",
                         "spotify:track:0scrtPmtlIVwwk9s4LXJ8n",
                         "spotify:track:3zRliQqUlisnnl3BguDkZM",
                         "spotify:track:6gmeXarVRe4ZBBKjXepRAC",
                         "spotify:track:7odHgoLFi3GQ90E9PeraI3"
                      ]
                   }
                ]
             }
          }
       },
       "status":"normal",
       "tags":[
          "minecraft"
       ]
    }
    
  2. # 2 楼答案

    这是JSON格式,或者至少看起来是这样,有JSON的java解析器,所以尝试使用它,它将生成映射,而不是数组