Accessing members of items in a JSONArray with Java

后端 未结 6 1586
小蘑菇
小蘑菇 2020-11-22 16:23

I\'m just getting started with using json with java. I\'m not sure how to access string values within a JSONArray. For instance, my json looks like this:

{
         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 16:54

    By looking at your code, I sense you are using JSONLIB. If that was the case, look at the following snippet to convert json array to java array..

     JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( input );  
     JsonConfig jsonConfig = new JsonConfig();  
     jsonConfig.setArrayMode( JsonConfig.MODE_OBJECT_ARRAY );  
     jsonConfig.setRootClass( Integer.TYPE );  
     int[] output = (int[]) JSONSerializer.toJava( jsonArray, jsonConfig );  
    

提交回复
热议问题