乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      java – 如何將JSON對(duì)象解析為`Map>`

       印度阿三17 2019-05-19

      我想解析這個(gè)JSON對(duì)象:

      "{
        \"Rao\":[\"Q7293658\",\"\",\"Q7293657\",\"Q12953055\",\"Q3531237\",\"Q4178159\",\"Q1138810\",\"Q579515\",\"Q3365064\",\"Q7293664\",\"Q1133815\"],
        \"Hani Durzy\":[\"\"],
        \"Louise\":[\"\",\"Q1660645\",\"Q130413\",\"Q3215140\",\"Q152779\",\"Q233203\",\"Q7871343\",\"Q232402\",\"Q82547\",\"Q286488\",\"Q156723\",\"Q3263649\",\"Q456386\",\"Q233192\",\"Q14714149\",\"Q12125864\",\"Q57669\",\"Q168667\",\"Q141410\",\"Q166028\"],
        \"Reyna\":[\"Q7573462\",\"Q2892895\",\"Q363257\",\"Q151944\",\"Q3740321\",\"Q2857439\",\"Q1453358\",\"Q7319529\",\"Q733716\",\"Q16151941\",\"Q7159448\",\"Q5484172\",\"Q6074271\",\"Q1753185\",\"Q7319532\",\"Q5171205\",\"Q3183869\",\"Q1818527\",\"Q251862\",\"Q3840414\",\"Q5271282\",\"Q5606181\"]
      }"
      

      并使用該數(shù)據(jù)生成Map< String,HashSet< String>>.

      基本上我想要逆轉(zhuǎn)this程序.

      這個(gè)項(xiàng)目的所有代碼都可以在on my github page here找到,它很短.

      更新

              File f = new File("/home/matthias/Workbench/SUTD/nytimes_corpus/wdtk-parent/wdtk-examples/JSON_Output/user.json");
      
              String jsonTxt = null;
      
              if (f.exists())
              {
                  InputStream is = new FileInputStream("/home/matthias/Workbench/SUTD/nytimes_corpus/wdtk-parent/wdtk-examples/JSON_Output/user.json");
                  jsonTxt = IOUtils.toString(is);
      
      
              }
              //System.out.println(jsonTxt);
      
      
              Gson gson=new Gson(); 
      
      
              Map<String, HashSet<String>> map = new HashMap<String, HashSet<String>>();
              map=(Map<String, HashSet<String>>) gson.fromJson(jsonTxt, map.getClass());
      
              //// \\ // ! PRINT IT ! // \\ // \\ // \\ // \\ // \\ // \       for (Map.Entry<String, HashSet<String>> entry : map.entrySet()) 
             {
                 System.out.println(entry.getKey() " : "   Arrays.deepToString(map.entrySet().toArray()) );
             }
      

      解決方法:

      使用Gson

      Gson gson = new Gson(); 
      String json = "<YOUR_JSON_STRING_HERE>";
      Map<String, HashSet<String>> map = new HashMap<String, HashSet<String>>();
      map = (Map<String, HashSet<String>>) gson.fromJson(json, map.getClass());
      

      更新:

      使用TypeToken

      Type type = new TypeToken<Map<String, HashSet<String>>>(){}.getType();
      map = (Map<String, HashSet<String>>) gson.fromJson(json, type);
      

      或者你可以解析它……

      >創(chuàng)建一個(gè)JSONObject的對(duì)象
      >創(chuàng)建HashMap的對(duì)象
      >迭代jsonObj.keys()并為每個(gè)鍵獲取值
      jsonObj.getString(鍵).
      >將它放在map.put(key,value)中.

      來源:http://www./content-1-198551.html

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請遵守用戶 評(píng)論公約

        類似文章 更多