JSON Java Simple-json

Source: Internet
Author: User

Http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-1_-_Encode_a_JSON_object

JAVAC-CP./json-simple.jar Splitdemo.java

JAVA-CP _classpath:./json-simple.jar Splitdemo

 Public classQueryAttributeImplementsJsonstreamaware {PrivateString query; PrivateString Cat; Private intGuanwang; PrivateString icon; PrivateString Entity_name; Private Doublescore; PrivateString Clkurl;  PublicQueryAttribute (String query,Doublescore, String cat, String entity_name,intGuanwang, string icon, string clkurl) {      This. query =query;  This. cat =Cat;  This. Entity_name =Entity_name;  This. score =score;  This. Guanwang =Guanwang;  This. Icon =icon;  This. Clkurl =Clkurl; }    Public voidWritejsonstring (Writer out)throwsioexception {linkedhashmap obj=NewLinkedhashmap (); Obj.put ("Query", query); Obj.put ("Score", score); Obj.put ("Cat", cat); Obj.put ("Ename", Entity_name); Obj.put ("GW", Guanwang); Obj.put ("Icon", icon); Obj.put ("Clkurl", Clkurl);   Jsonvalue.writejsonstring (obj, out); }}

Parser

ImportOrg.json.simple.JSONObject;ImportOrg.json.simple.JSONArray;ImportOrg.json.simple.JSONValue;ImportJava.util.*; Public classsegment{ Public Static voidMain (string[] args) {String s= "[0,{\" 1\ ": {\" 2\ ": {\" 3\ ": {\" 4\ ": [5,{\" 6\ ": 7}]}}}]"; Object obj=Jsonvalue.parse (s); Jsonarray Array=(jsonarray) obj; System.out.println (Array.get (0)); System.out.println (Array.get (1));        System.out.println (); Jsonobject Obj2= (Jsonobject) array.get (1); System.out.println ("=============field \" 1\ "======="); System.out.println (Obj2.get ("1"));        System.out.println (obj); S= "{}"; Obj=Jsonvalue.parse (s);        System.out.println (obj); S= "[5,]"; Obj=Jsonvalue.parse (s);        System.out.println (obj); S= "[5,,2]"; Obj=Jsonvalue.parse (s);    System.out.println (obj); }}

JSON Java Simple-json

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.