当前位置: 首页 > 知识库问答 >
问题:

JSON响应不完整,但在浏览器中可以

潘刚洁
2023-03-14

当我在检查响应后向服务器发送请求时,我发现不完整的JSON响应。我用凌空抽射,怎么解决?

{"mostviewedvideos":[{"id":"18253295","title":"\u06a9\u062c\u0627\u0628\u0631\u06cc\u0645 \u0642\u0633\u0645\u062a5 \/ \u0641\u0633\u062a \u0641\u0648\u062f \u062a\u0648\u0633\u06a9\u0627","username":"hormozgantv","userid":"3362417","visit_cnt":464,"uid":"JiE8T","isHidden":false,"process":"done","big_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18253295-9314-b__533446055.jpg","small_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18253295-9314__8805.jpg","profilePhoto":"https:\/\/www.aparat.com\/public\/public\/user_data\/profile_photo\/1121\/3362417-m.jpg","duration":448,"sdate":"21 \u0622\u0630\u0631 1398","create_date":"2019-12-12 13:06:59","sdate_timediff":168361,"frame":"https:\/\/www.aparat.com\/video\/video\/embed\/videohash\/JiE8T\/vt\/frame","official":"yes","autoplay":true,"video_date_status":"notset","360d":false,"deleteurl":""},{"id":"18261013","title":"\u0622\u0645\u0648\u0632\u0634 \u0631\u0648\u0627\u0646\u0634\u0646\u0627\u0633\u06cc: \u0628\u0647 \u062e\u0627\u0637\u0631 \u0639\u0634\u0642\u062a \u0627\u0632 \u062e\u0648\u062f\u062a \u0646\u06af\u0630\u0631","username":"halimeh_basefat","userid":"6317482","visit_cnt":788,"uid":"tSwQV","isHidden":false,"process":"done","big_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18261013-7821-b__699295836.jpg","small_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18261013-7821__7696.jpg","profilePhoto":"https:\/\/www.aparat.com\/public\/public\/user_data\/profile_photo\/2106\/6317482-m.jpg","duration":165,"sdate":"21 \u0622\u0630\u0631 1398","create_date":"2019-12-12 22:06:51","sdate_timediff":135969,"frame":"https:\/\/www.aparat.com\/video\/video\/embed\/videohash\/tSwQV\/vt\/frame","official":"yes","autoplay":true,"video_date_status":"notset","360d":false,"deleteurl":""},{"id":"18276419","title":"\u062a\u0627\u06cc\u0645 \u0644\u0650\u067e\u0633 \u06af\u0648\u0634\u062a \u0686\u0631\u062e \u0634\u062f\u0647 - Minced Meat TimeLapse","username":"meysam.ahwazi","userid":"2653435","visit_cnt":1138,"uid":"xiYy1","isHidden":false,"process":"done","big_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18276419-4985-b__189630358.jpg","small_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18276419-4985__9388.jpg","profilePhoto":"https:\/\/www.aparat.com\/public\/public\/user_data\/profile_photo\/885\/2653435-m.jpg","duration":314,"sdate":"22 \u0622\u0630\u0631 1398","create_date":"2019-12-13 19:55:27","sdate_timediff":57453,"frame":"https:\/\/www.aparat.com\/video\/video\/embed\/videohash\/xiYy1\/vt\/frame","official":"no","autoplay":true,"video_date_status":"notset","360d":false,"deleteurl":""},{"id":"18238407","title":"\u0641\u06cc\u0644\u0645 \u0633\u06cc\u0646\u0645\u0627\u06cc\u06cc 23 \u0646\u0641\u0631","username":"owjmedia","userid":"3275514","visit_cnt":1438,"uid":"VsfQ2","isHidden":false,"process":"done","big_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18238407-6210-b__612861992.jpg","small_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18238407-6210__3438.jpg","profilePhoto":"https:\/\/www.aparat.com\/public\/public\/user_data\/profile_photo\/1092\/3275514-m.jpg","duration":59,"sdate":"20 \u0622\u0630\u0631 1398","create_date":"2019-12-11 14:09:23","sdate_timediff":251017,"frame":"https:\/\/www.aparat.com\/video\/video\/embed\/videohash\/VsfQ2\/vt\/frame","official":"yes","autoplay":true,"video_date_status":"notset","360d":false,"deleteurl":""},{"id":"18273908","title":"\u062e\u0634\u0645 \u0645\u0631\u062f\u0645 \u06af\u06cc\u0644\u0627\u0646 \u0627\u0632 \u0633\u0631\u06cc\u0627\u0644 \u00ab\u0648\u0627\u0631\u0634\u00bb","username":"kelaket.com","userid":"750710","visit_cnt":31091,"uid":"azfQ3","isHidden":false,"process":"no_stat","big_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18273908-6376-b__412519292.jpg","small_poster":"https:\/\/static.cdn.asset.aparat.com\/avt\/18273908-6376__4969.jpg","profilePhoto":"https:\/\/www.aparat.com\/public\/public\/user_data\/profile_photo\/251\/750710-m.jpg","duration":132,"sdate":"22 \u0622\u0630\u0631 1398","create_date":"2019-12-13 17:
 JSONObject object = new JSONObject(res);
            String aparat = object.getString("mostviewedvideos");

            JSONArray jsonArray = new JSONArray(aparat);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Items item = new Items();
                item.setTitle(jsonObject.getString("title"));
                item.setImageUrl(jsonObject.getString("small_poster"));
                item.setDate(jsonObject.getString("sdate"));
                item.setUsername(jsonObject.getString("username"));
                item.setAdvertising("none");
            }

共有1个答案

徐帅
2023-03-14

我已经使用FastandRoidNetworking记录了您需要的数据。请参见示例代码:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getData();

}

private synchronized void getData() {
    OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
            .connectTimeout(15, TimeUnit.SECONDS)
            .readTimeout(15, TimeUnit.SECONDS)
            .writeTimeout(15, TimeUnit.SECONDS)
            .build();

    AndroidNetworking.initialize(this, okHttpClient);

    AndroidNetworking.get("https://www.aparat.com//etc/api/mostviewedvideos")
            .setPriority(Priority.HIGH)
            .addHeaders("Content-Type", "application/json")
            .build()
            .getAsJSONObject(new JSONObjectRequestListener() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        String aparat = response.getString("mostviewedvideos");

                        JSONArray jsonArray = new JSONArray(aparat);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);

                            String title = jsonObject.getString("title");
                            String small_poster = jsonObject.getString("small_poster");
                            String sdate = jsonObject.getString("sdate");
                            String username = jsonObject.getString("username");

                            Log.i("data", title + "\n" + small_poster + "\n" + sdate + "\n" + username + "\n");
                        }
                    }catch (JSONException e){
                        e.printStackTrace();
                    }
                }

                @Override
                public void onError(ANError anError) {
                    errorHandler(anError);
                }
            });
}

public void errorHandler(ANError error) {
    if (error.getErrorCode() != 0) {

        Log.e("onError errorCode", "onError errorCode : " + error.getErrorCode());
        Log.e("onError errorBody", "onError errorBody : " + error.getErrorBody());
        Log.e("onError errorDetail", "onError errorDetail : " + error.getErrorDetail());

    } else {
        Log.e("onError errorDetail", "onError errorDetail : " + error.getErrorDetail());
        Log.e("onError errorBody", "onError errorBody : " + error.getResponse());

    }
}

}

查看此文档和使用步骤。

 类似资料:
  • 我尝试使用ETAG从api请求缓存json响应。我调用类似http://localhost:3000/api/config的代码,并获取: Thx响应。

  • 出于某种原因,如果我通过浏览器或MockMVC测试类访问Spring控制器,它会返回不同的响应。有人能帮我找出原因吗? 首先控制器方法: 显然,里面有一些未知的类扩展了,并包含一个名为的列表。这还扩展了。 当我通过浏览器访问代码时,我会得到以下内容: 看起来我很顺从。但当我通过MockMVC请求时。。。 响应中没有HATEOAS兼容元素,因此我的测试在jsonPath检查中失败: 我已经尝试过为M

  • 问题内容: 我想在javascript /浏览器中启用ajax响应的缓存。 从jquery.ajax docs : 默认情况下,始终发出请求,但浏览器可能会在其缓存之外提供结果。要禁止使用缓存的结果,请将cache设置为false。如果自上次请求以来未修改资产,则导致请求报告失败,请将ifModified设置为true。 但是,这些地址都没有强制缓存。 动机: 我想在我的初始化函数中放入调用,其中

  • 问题内容: 我正在通过jQuery的getJson()调用跨域Web服务。由于响应对象的大小很大,因此我在Web服务中使用了最大的JSon大小。我已经检查过getJson()提供正确的响应对象。但是仍然没有调用我的回调函数。Firebug表示已超过(firefox)响应大小。 谁能告诉我标准浏览器(例如,Firefox)处理的最大浏览器响应大小限制是多少,以及如何处理该问题? 这是相同的代码段。

  • APIService: 在活动调用API中:

  • 我正在使用Volley向API发出GET请求: 预期的JSON对象响应很大(可能高达500 KB)。我无法在日志中看到完整的响应。仅显示前50行左右。我还得到了info: BasicNetwork.log慢速请求:请求的HTTP响应= 这意味着请求需要超过3000毫秒。 尝试过的事情: 我已经在手机的开发者选项中将记录器缓冲区大小增加到1M。 原因可能是什么?当它很大的时候,响应是大块发送的吗?如