티스토리 뷰

반응형

 private void parsingJacson(String jsonStr)
{
  JavaData javaData = null;
  ObjectMapper om = new ObjectMapper();
  try
  {

//  Map<String, Object> m = om.readValue(jsonStr,new TypeReference<Map<String, Object>>(){});

   JsonNode root = om.readTree(jsonStr);

   // 배열에 있는 값들 가져오기
   boolean success = root.path("success").getBooleanValue();
   if(success)
   {
    JsonNode data = root.path("data");
    JsonNode ext1 = root.path("extData1");
     JsonNode ext2 = root.path("extData2");
    JsonNode ext3 = root.path("extData3");
    
    System.out.println("uIdx = "+ext1.path("uIdx").asInt();
    System.out.println("nickName = "+ext1.path("nickName").asText();
   
    List<String> typeList = root.path("messages").findValuesAsText("type");
    int arraySize = typeList.size();
    for (String string : typeList)
    {
        System.out.println("type::::" + string);
    }
   }
  }
  catch (Exception e)
  {
   // TODO: handle exception
  }
}

 

ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡjson 데이터ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

 

{
  "exData1": {
    "uIdx": 123,
    "uId": "abcdefg",
    "nickName": "길동이",
    "currentStage": 3
  },
  "exData2": {
    "cAmount": 13,
    "hType": "Yes"
  },
  "data": {
    "index": 2,
    "status": "default"
  },
  "success": true,
  "messages": [
    {
      "nextStage": 4,
      "nextPower": 85,
      "type": "Jump"
    },
    {
      "message": "점프되었습니다.",
      "type": "msg"
    }
  ]
}

 

 

 

출처 : http://gubok.tistory.com/294

반응형