简体   繁体   English

Okhttp JSON 解析

[英]Okhttp JSON Parsing

I'm trying to parse a Json data with the following code:我正在尝试使用以下代码解析 Json 数据:

OkHttpClient client = new OkHttpClient().newBuilder().build();
Request request = new Request.Builder()
                .url("http://datamall2.mytransport.sg/ltaodataservice/BusServices")
                .method("GET", null)
                .addHeader("AccountKey", "XXXX==")
                .addHeader("accept", "application/json")
                .build();
Response response = client.newCall(request).execute();

The two errors that I'm facing are:我面临的两个错误是:

error: cannot find symbol method newBuilder()

and

unhandled exception error for .execute();.

根据https://square.github.io/okhttp/你只需要做:

OkHttpClient client = new OkHttpClient();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM