相同的json

时间:2018-10-23 15:36:55

标签: java android json

(对不起,我是我的英语,我不是母语人士)。 添加: 我已经直接通过网络编辑了json。对于要更改的元素,有时是字符串“”,有时是数组[],为空或完整。我已经尝试过使用List,String,ArrayList和Array [],但它始终有一个错误(但不在同一位置)。 这是失败的方法的代码:

   @Override
   protected void LoadingNews() {
     this.mDisposable = NewsStreams.MostPopularStream(0)
     .subscribeWith(new DisposableObserver<MostPopularStructure>(){
        @Override
        public void onNext(MostPopularStructure mostPopularStructure) {
               mMostPopularResults = mostPopularStructure.getResults();
               UpdateRecyclerView();
               mNewsAdapter.notifyDataSetChanged();
               }
        @Override
        public void onError(Throwable e) {
               Log.e("News","MostPopular.LoadingNews : Error : " + e.getMessage());
               }
        @Override
        public void onComplete() {
        }
    });
}

这是MostPopularStructure的摘录:

public class MostPopularStructure {

@SerializedName("status")
@Expose
private String status;
@SerializedName("copyright")
@Expose
private String copyright;
@SerializedName("num_results")
@Expose
private Integer numResults;
@SerializedName("results")
@Expose
private List<MostPopularResult> results = null;

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
} …

…和类MostPopularResult哪里出了问题:

public class MostPopularResult {

    @SerializedName("url")
    @Expose
    private String url;
    …
    @SerializedName("des_facet")
    @Expose
    private List<String> desFacet = null;
    **@SerializedName("org_facet")
    @Expose
    private List<String> orgFacet = null;**
    @SerializedName("per_facet")
    @Expose
    private List<String> perFacet = null;
    @SerializedName("geo_facet")
    @Expose
    private List<String> geoFacet = null;
    @SerializedName("media")
    @Expose
    private List<Medium> media = null;

    public String getUrl() {
        return url;
    } …

以及List试用期间的错误消息:

E/News: MostPopular.LoadingNews : Error : java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 822 path $.results[0].org_facet

String试用期间的错误消息(我已将orgfacet的类型更改为String):

E/News: MostPopular.LoadingNews : Error : java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 3786 path $.results[1].org_facet

对于使用ArrayList和Array []类型的试验,我有与第一次试验相同的信息。

紧随其后的是json(这只是节选,原始内容包含62,000个字符以上!):

{"status":"OK",
"copyright":"Copyright (c) 2018 The New York Times Company.  All Rights Reserved.",
"num_results":1545,
"results":[
{"url":"https:\/\/www.nytimes.com\/2018\/10\/24\/nyregion\/clinton-obama-explosive-device.html",
"adx_keywords":"Bombs and Explosives;Clinton, Hillary Rodham;Soros,  George;Clinton, Bill;Obama, Barack",
"column":null,
"section":"New York",
"byline":"By WILLIAM K. RASHBAUM",
"type":"Article",
"title":"Hillary Clinton, Barack Obama and CNN Offices Are Sent Pipe Bombs",
"abstract":"The similar devices sparked an intense investigation into whether a bomber is going after targets that have often been the subject of right-wing ire.",
"published_date":"2018-10-24",
"source":"The New YorkTimes",
"id":100000006177826,
"asset_id":100000006177826,
"views":1,"des_facet":["BOMBS AND EXPLOSIVES"],
**"org_facet":""**,
"per_facet":["CLINTON, HILLARY RODHAM","SOROS, GEORGE","CLINTON, BILL","OBAMA, BARACK"],
"geo_facet":"",
"media":[ …]
 },
{"url":"https:\/\/www.nytimes.com\/2018\/10\/23\/nyregion\/man-found-dead-in-car-new-york.html",
"adx_keywords":"Weglarz, Geoffrey (Geoffrey Corbis);Missing Persons;East Village (Manhattan, NY);Suicides and Suicide Attempts",
"column":null,
"section":"New York",
"byline":"By MICHAEL WILSON",
"type":"Article",
"title":"His Body Was Behind the Wheel for a Week Before It Was Discovered. This Was His Life.",
"abstract":"A software designer ended his life in his parked car in the East Village. His family asked the police for help finding him, but met resistance.",
"published_date":"2018-10-23",
"source":"The New York Times",
"id":100000006138513,
"asset_id":100000006138513,
"views":2,
"des_facet":"",
**"org_facet":["MISSING PERSONS","SUICIDES AND SUICIDE ATTEMPTS"],**
"per_facet":["WEGLARZ, GEOFFREY (GEOFFREY CORBIS)"],
"geo_facet":["EAST VILLAGE (MANHATTAN, NY)"],
"media":[…]},
 …}

感谢您的帮助和/或建议。

1 个答案:

答案 0 :(得分:0)

您可以更改“最受欢迎”结构以仅保留所需的数据,因此您应该从其中删除所有%-facet。