[英]Jackson vs Simple Json Parser
使用Simple JSONParser將字符串解析為JSONObject,並且沒有問題。 后來聽到傑克遜解析器的聲音,它比Simple JSONParser更快。 但是問題是,在通過Jackson解析器進行解析之后,如果jsonobject中存在一個jsonobject,則無法提取內部jsonobject,這在Simple JSONParser中不是這種情況,並且更加容易。
例如:{“ Key1”:“ Value1”,“ Key2”:{“ innerJSonKey”:“ innerJSonValue”}}}這是使用toString()轉換為String的jsonobject。
JSON簡單
JSONParser jp = new JSONParser();
JSONObject jo = (JSONObject)jp.parse(jsonString);
JSONObject innerjson = (JSONObject)jo.get("innerJSonKey"); -- this pretty much works
傑克遜
ObjectMapper mapper = new ObjectMapper();
JSONObject jo = mapper.readValue(jsonString,JSONObject.class);
JSONObject innerjson = (JSONObject)jo.get("innerJSonKey"); -- **But this step is failing**
請發表您的評論,無論我是做任何錯誤還是有解決方案
您可以嘗試以下代碼來獲取與innerJSonKey
對應的值
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readValue(jsonString, JsonNode.class);
JsonNode innerNode = rootNode.get("Key2").get("innerJSonKey");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.