Now sometimes the previous item needs to be returned to modify the bug to see the following code
1 if(Test! =NULL) {2Jsontokener Jsonparser =NewJsontokener (test);3Jsonobject Data_jo =(Jsonobject) jsonparser.nextvalue ();4String data_str = data_jo.getstring ("Datemap");5 6 if(!data_str.equals ("")){7Jsonarray ry = (Jsonarray)NewJsontokener (DATA_STR)8 . NextValue ();9arraylist<jsonobject> list =NewArraylist<jsonobject>();Ten One /**traversal fetch data Bean*/ A for(intI=0;i<ry.length (); i++){ -Jsonobject Jo =Ry.getjsonobject (i); - the /**set in the object according to the defined field and the field returned by the server*/ - List.add (Jo); - } - returnlist; +}Else { - return NULL; + } A}Else { at return NULL; -}
Yes, parsing the server-side back to the JSON format data, is not the mind of 10,000 grass mud horse in the Pentium, I guarantee that this inefficient day is gone, Gson+gsonformat+postman let parsing json become more enjoyable.
First, say Gson.
Wikipedia says Gson(also known as Google Gson) is an open-source Java library released by Google, primarily intended for serializing Java objects as JSON strings, or deserializing JSON strings into Java objects, which is easy to understand.
We add Gson support to the project (IDE as)
Click File, Project Structure and then look at:
Next we type search Gson to search results and then select Click OK button continuously
Then we'll go to the Gradler file and find out.
Front is a way to add Gson, in fact, we can go directly to the grader file dependencies add
Compile ' com.google.code.gson:gson:2.8.1 '
After Gson said Gsonformat, after the above steps, we can freely switch the serialization of Java objects and JSON strings in the code, for example
Or
But if we were to create the corresponding serialized Java object for ourselves after receiving the server string, if the simple JSON string is still complex, then the efficiency is too low, so we need to Gsonformat
Click File--settings->plugins to search for Gsonformat and restart as, now let's test it, we'll create a Test.java
Then the right mouse button->generate->gsonformat, enter the JSON string, click OK
Well, that's when our bean is done.
The efficiency has been greatly improved by this set of processes, but we can go a step further and think about where our data came from, what we got from the break point in Android code? Wouldn't it be exhausting, an interface to hit a breakpoint, a background developer to provide the interface documentation? What if the development cycle is short and not available? Can not wait, then we dragged the progress, blame it down or we have to carry, this time postman on the play
Postman is a super-powerful Chrome plugin for sending HTTP requests, let's take a look at how to install
To open chrome, click the extensions, more tools, ≡, top right corner, and pull to the bottom to click for more extensions
Finally, let's see how to use it.
After getting the results above, we create a new Java serialization object, then Gsonformat, and finally You love Gson.tojson () or Gson. Fromjson (), you like it.
Gson+gsonformat+postman Simple Rough parsing json