1
相关Question在Android改造响应中获取JsonSyntaxException?
的Json
响应是New line delimiter Json
:
{"type":"data","id":"xyz"}
{"type":"value","id":"xcf"}
....
....
我使用Retrofit
作出要求:
public void getWarehouse(){
//Generation of RestAdapter
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(URL)
.setLogLevel(RestAdapter.LogLevel.FULL)
.setLog(new AndroidLog("= NETWORK ="))
.build();
//Making request to API
adapter.create(WarehouseAPI.class).getWarehouse()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Response>() {
@Override
public void onCompleted() {
Log.d(this.getClass().getName(), "OnCompleted()");
}
@Override
public void onError(Throwable e) {
Log.d(this.getClass().getName(), "Error:" + e.toString());
}
@Override
public void onNext(Response response) {
System.out.println("test");
}
});
}
我可以看到我的Android Studio console
响应,但得到以下错误:
错误
- 响应
可能性是
NdJson
,它不能够正确地解析它
问题
- 我怎样才能正确分析?
你想读取它作为一个数组?如果您的回复包裹在[]中? –
@ trevor-e其实它不是'NdJson'。所以没有'JsonArray'或'JsonObject'在这里工作。请看看这个问题:http://stackoverflow.com/questions/15121584/how-to-parse-a-large-newline-delimited-json-file-by-jsonstream-module-in-node-j (如果我没有错) –
我明白了。我相信你需要指定一个客户转换器来改造以处理这个,可能使用一个自定义的Gson对象。 –