zoukankan      html  css  js  c++  java
  • JAVA下JSON的类型输出及使用

    JSON类型的输出:

    import java.util.ArrayList;
    import java.util.HashMap;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    import org.json.*;
    import java.io.*;  
    
    public class CESHI{
    	
        public String CESHI_()
        {
        	ArrayList lst=new ArrayList();
        	
        	HashMap map=new HashMap();  
        	
        	map.put("苹果","G001");
        	map.put("香蕉","G002");
        	map.put("西瓜","G003");
        	map.put("菠萝","G004");
        	
        	lst.add(map); 
        	
        	return JSONArray.fromObject(lst).toString();
        }
        
    }
    

    JSON类型的对象实例化及使用:

    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    
    public class starts {
    	public static void main(String[] args) {  
    		  
    		JSONArray jsonArray=JSONArray.fromObject(字符串);
    		
    		for(int i=0;i<jsonArray.size();i++)
    		{
    			JSONObject jsonObj=(JSONObject)jsonArray.get(i);
    			System.out.println(jsonObj.get(KEYNAME));
    		}
    		
        }  
    
    }
    

      

  • 相关阅读:
    交换相邻字符(CharBuffer)
    ANSI和UNICODE
    关键路径
    拓扑排序 java
    MySql 中group by使用
    面试题2
    面试题
    K8S如何限制资源使用
    Kubernetes中配置Pod的liveness和readiness探针
    sed入门详解教程
  • 原文地址:https://www.cnblogs.com/fan-yuan/p/4011555.html
Copyright © 2011-2022 走看看