As an Android development beginner, it's hard to find a solution, share with you,
It's really simple, just keep the file on the server (Date2.json) as it is encoded in the software.
I use Android Studio is Utf-8, so the server file (Date2.json) encoded in the way also set a value of utf-8;
Create a new text document, write the content, save the file as to the Htdocs folder under the server folder, and change the. txt to. JSON, encoded as Utf-8
The direct save is complete.
To run the program results:
Send request to get JSON file private void Sendrequestbyokhttp () {New Thread (new Runnable () {@Override public void Run () {try {okhttpclient client = new Okhttpclient (); Request Request = new Request.builder (). URL ("Http://10.0.2.2:88/data2.json")//I built a server locally , Date2.json. Build (); Response Response = client.newcall (Request). Execute (); String responsedata = Response.body (). String (); Parsejsonobject (ResponseData); } catch (Exception e) {e.printstacktrace (); }}). Start (); } private void Parsejsonobject (String json) {try {Jsonarray Jsonarray = new Jsonarray (JSON); for (int i = 0; i < jsonarray.length (); i++) {Jsonobject jsonobject = Jsonarray.getjsonobject (i); String id = jsonobject.getstring ("id"); String name = jsonobject.getstring ("name"); LOG.D ("Mainactivity", "name is" + name); LOG.D ("Mainactivity", "ID is" + ID); }} catch (Jsonexception e) {e.printstacktrace (); } }
Need a complete code can comment to find I want to
Android Studio parsing json file appears Chinese garbled solution