Three ways: 1, all parse out; 2, what to parse what; 3,jsonreader, 1th/2 strokes explained above, the following example Jsonreader (similar to the node-wise interpretation of XML) Through the Jsonreader way to parse private void Parsecomplexjarraybyreader () throws IOException { String Strbyjson = Jsontostringutil.getstringbyjson (this, r.raw.juser_4); Jsonreader reader = new Jsonreader (new StringReader (Strbyjson)); try { Reader.beginobject (); String tagName = Reader.nextname (); if (Tagname.equals ("group")) { Read Group this node Readgroup (reader); } Reader.endobject (); } finally { Reader.close (); } } Read Group this node private void Readgroup (Jsonreader reader) throws IOException { Reader.beginobject (); while (Reader.hasnext ()) { String tagName = Reader.nextname (); if (tagname.equals ("user")) { Readuser (reader); } else if (tagname.equals ("info")) { Readinfo (reader); } } Reader.endobject (); } Read the user basic message the Users node private void Readuser (Jsonreader reader) throws IOException { Reader.beginobject (); while (Reader.hasnext ()) { String tag = Reader.nextname (); if (tag.equals ("name")) { String name = Reader.nextstring (); Nametext.settext (name); } else if (Tag.equals ("Age")) { String age = reader.nextstring (); Agetext.settext (age); } ... else { Reader.skipvalue ();//Ignore } } Reader.endobject (); } Read user other Messages Info node private void Readinfo (Jsonreader reader) throws IOException { Reader.beginobject (); while (Reader.hasnext ()) { String tag = Reader.nextname (); if (Tag.equals ("address")) { String address = reader.nextstring (); Addresstext.settext (address); } else if (Tag.equals ("work")) { String work = reader.nextstring (); Worktext.settext (work); } ... else { Reader.skipvalue ();//Ignore } } Reader.endobject (); } |