JSON: Nested Array

前端 未结 1 1290
-上瘾入骨i
-上瘾入骨i 2020-12-21 17:39

I have a program that retrieves data from a Database (data store in JSON MySQL).

public static int selectData(Connection conn, String db_type) throws SQLExce         


        
相关标签:
1条回答
  • 2020-12-21 18:12

    You can use Jackson Api to achieve this.
    You have to create Pojo class same as your json object (Class should have members like 'attributes','uuid').
    This are classes you have to use

    com.fasterxml.jackson.core.JsonFactory;
    com.fasterxml.jackson.core.JsonParser;
    com.fasterxml.jackson.databind.ObjectMapper;
    

    And code

    ObjectMapper objMapper=new ObjectMapper();
    JsonFactory jfactory = new JsonFactory();
    JsonParser jParser=jfactory.createJsonParser(jsonString); //json Object as String
    
    Mapperclass mapper=objMapper.readValue(jParser,Mapperclass.class);// Mapperclass is Pojo for your jsonObject
    

    Now you can use getter methods of Mapperclass to get you json attributes in java object or Arrays etc like

     String uuid=mapper.getUuid();
    
    0 讨论(0)
提交回复
热议问题