Response对象转utf-8

 String responseBody = response.body().string();

 try {
            JSONObject jsonObject = new JSONObject(responseBody);

            // 获取需要的字段,示例中获取msg和data.info字段
            int status = jsonObject.getInt("status");
            String msg = jsonObject.getString("msg");
            JSONObject data = jsonObject.getJSONObject("data");
            String info = data.getString("info");

            // 输出结果
           System.out.println("status: " + status);
            System.out.println("msg: " + msg);
            System.out.println("data: " + data);
            System.out.println("info: " + info);


            schoolDao schooldao = faceRoomDatabase.schoolDao();
            schoolEntity school = new schoolEntity();
            school.setInfo(info);
            schooldao.insert(school);

        } catch (JSONException e) {
            e.printStackTrace();
        }

]

记录:http请求

package com.arcsoft.arcfacedemo.dbutil;

import android.util.Log;

import java.io.IOException;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import android.os.Handler;
import android.os.Looper;

import org.json.JSONException;
import org.json.JSONObject;

public  class GetInformation {

    private static final String TAG = "GetInformation";
    private static OkHttpClient okHttpClient;
    private Handler handler = new Handler();
    private Runnable runnable;
    private Handler mHandler = new Handler(Looper.getMainLooper());
    private Runnable mPollingRunnable;
    private Runnable pollingRunnable;
    private static FaceRoomDatabase faceRoomDatabase;

    public static void asd() {
        okHttpClient = new OkHttpClient();
        faceRoomDatabase = FaceRoomDatabase.getInstance(ArcFaceApp.getApplication());
        new Thread() {
            @Override
            public void run() {
                try {
                    // 设置正确的URL
                    String url = "********************";
                    Request request = new Request.Builder()
                            .url(url) // 使用完整的URL
                            .build();
                    OkHttpClient okHttpClient = new OkHttpClient(); 

                    Call call = okHttpClient.newCall(request);
                    Response response = call.execute();
                    if (response.isSuccessful()) {
                        String responseBody = response.body().string();
                        toSql(responseBody);
                    } else {
                        Log.e(TAG, "Request  " + response.code());
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }


    public static void toSql(String responseBody) {
        try {
            JSONObject jsonObject = new JSONObject(responseBody);

            // 获取需要的字段,示例中获取msg和data.info字段
            int status = jsonObject.getInt("status");
            String msg = jsonObject.getString("msg");
            JSONObject data = jsonObject.getJSONObject("data");
            String info = data.getString("info");

            // 输出结果
           System.out.println("status: " + status);
            System.out.println("msg: " + msg);
            System.out.println("data: " + data);
            System.out.println("info: " + info);

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值