Android Studio parsing json file appears Chinese garbled solution

Source: Internet
Author: User

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

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.