The Java wrapper parses the JSON data.

Source: Internet
Author: User

Import Java.util.hashmap;import java.util.iterator;import Java.util.list;import Java.util.map;import Java.util.vector;import Com.alibaba.fastjson.jsonarray;import Com.alibaba.fastjson.jsonobject;import Com.led.image.transformutils;import com.ledsystem.util.encodingdetect;/** * @deprecated 锛 氳 canвt 鏋 manic son indent dress depleting * @author Gary Huang * @since: 1.0.0 * */@SuppressWarnings ("Unchecked") public class Jsonarrayutils {private list<nodeobject> nod ES = null;p ublic jsonarrayutils (String json) {try {Jsonarray Jsonarray = Jsonarray.parsearray (JSON); nodes = Parsenodes (js Onarray);} catch (Exception e) {e.printstacktrace ();}} List<nodeobject> parsenodes (jsonarray array) {list<nodeobject> nodes = new vector<nodeobject> (); int Size = Array.size (); for (int i = 0; i < size; i++) {try {jsonobject json = array.getjsonobject (i); Nodes.Add (Parsenodeo Bject (JSON));} catch (Exception e) {e.printstacktrace ();}} return nodes; }nodeobject Parsenodeobject (Jsonobject json) {nodeobject node = newNodeobject ();iterator<string> key = Json.keyset (). Iterator (); while (Key.hasnext ()) {String keyName = transformutils.tostring (Key.next ()); try {Object value = Json.get (keyName); if (Nu  LL = = value) {continue;} if (value instanceof jsonobject) {node.put (KeyName, Parsenodeobject ((jsonobject) value));  }else if (value instanceof Jsonarray) {node.put (KeyName, Parsenodes ((Jsonarray) value)); }else{node.put (keyName, value);}} catch (Exception e) {e.printstacktrace ();}} return node;} Public list<nodeobject> Getnodes () {return nodes;} Public Nodeobject GetNode () {return nodes.get (0);} public static class Nodeobject{private map<string, object> datas = new hashmap<string, object> ();p ublic void P UT (String key, Object value) {datas.put (key, value);}  Public Object get (String key) {return datas.get (key); } @Overridepublic String toString () {return datas.tostring ();}} public static class Nodeitem{private string key;p rivate Object value;p ublic string GetKey () {return Key;} public void Setkey (String key) {This.key = key;} Public Object GetValue () {return value;} public void SetValue (Object value) {this.value = value,} public nodeobject GetNode () {return (Nodeobject) This.value;} Public list<nodeobject> Getnodes () {return ((list<nodeobject>) this.value); @Overridepublic String toString () {return "key:" + key + "value:" + Value;}}

The Java wrapper parses the JSON data.

Related Article

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.