相关疑难解决方法(0)

使用Retrofit和GSON解析JSON时,尝试解析并获取回调时出错.

我正在使用Retrofit处理针对Android应用程序的API调用.我试图让Retrofit处理JSON的解析,并根据我创建的POJO创建一个对象列表.

我收到的错误是" com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:预期字符串但在第1行第176行是BEGIN_OBJECT".

我使用JsonSchema2Pojo来生成我的java类.类和关联的JSON如下所示.

{"status":"success","data":[{"sort_key":1,"event_id":1947357,"title":"2014 US Open Tennis Session 15 (Mens\/Womens Round of 16)","datetime_utc":"2014-09-01T15:00:00","venue":{"city":"Flushing","name":"Louis Armstrong Stadium","extended_address":"Flushing, NY 11368","url":"https:\/\/seatgeek.com\/venues\/louis-armstrong-stadium\/tickets\/?aid=10918","country":"US","display_location":"Flushing, NY","links":[],"slug":"louis-armstrong-stadium","state":"NY","score":0.73523,"postal_code":"11368","location":{"lat":40.7636,"lon":-73.83},"address":"1 Flushing Meadows Corona Park Road","timezone":"America\/New_York","id":2979},"images":["https:\/\/chairnerd.global.ssl.fastly.net\/images\/performers-landscape\/us-open-tennis-45e2d9\/5702\/huge.jpg","https:\/\/chairnerd.global.ssl.fastly.net\/images\/performers\/5702\/us-open-tennis-c1ccf7\/medium.jpg","https:\/\/chairnerd.global.ssl.fastly.net\/images\/performers\/5702\/us-open-tennis-01f513\/large.jpg","https:\/\/chairnerd.global.ssl.fastly.net\/images\/performers\/5702\/us-open-tennis-4e07f2\/small.jpg"]}
Run Code Online (Sandbox Code Playgroud)

从此我相信我需要生成3个POJO,我的更高级别的"EventObject"类,位置类和Venue类.这些类及其变量如下:

EventObject类:

public class EventObject {

private Integer sortKey;
private Integer eventId;
private String title;
private String datetimeUtc;
private Venue venue;
private List<String> images = new ArrayList<String>();
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
Run Code Online (Sandbox Code Playgroud)

位置等级:

public class Location {

private Float lat;
private Float lon;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
Run Code Online (Sandbox Code Playgroud)

地点类别:

public …
Run Code Online (Sandbox Code Playgroud)

java json retrofit

5
推荐指数
1
解决办法
4279
查看次数

Android - 如何在Robospice/retrofit中获取JSON格式请求和响应

我是Robospice /改造图书馆的新手.我从github得到了一些样本.https://github.com/octo-online/RoboSpice-samples/tree/release/robospice-sample-retrofit.

我的理解:

请求是"githubRequest",响应是"Contributor.List".web服务由getSpiceManager().execute执行.

代码片段:

    @Override
        protected void onStart() {
            super.onStart();
            getSpiceManager().execute(githubRequest, "github", DurationInMillis.ONE_MINUTE, new ListContributorRequestListener());
    } 

public final class ListContributorRequestListener implements RequestListener<Contributor.List> {

    @Override
    public void onRequestFailure(SpiceException spiceException) {
        Toast.makeText(SampleSpiceActivity.this, "failure", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRequestSuccess(final Contributor.List result) {
        Toast.makeText(SampleSpiceActivity.this, "success", Toast.LENGTH_SHORT).show();
        updateContributors(result);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题:我想从应用程序检查请求/响应("githubRequest"/"Contributor.List")是否将正确的JSON发送到服务.那么如何sysout JSON请求和响应.但请求/响应是POJO对象.但是如果我想打印JSON请求和响应,我该怎么做?有人帮我这样做吗?

android json web-services robospice retrofit

2
推荐指数
1
解决办法
5253
查看次数

标签 统计

json ×2

retrofit ×2

android ×1

java ×1

robospice ×1

web-services ×1