第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用正則表達(dá)式通過(guò)服務(wù)器拆分響應(yīng)

如何使用正則表達(dá)式通過(guò)服務(wù)器拆分響應(yīng)

阿晨1998 2022-09-14 17:58:20
我想拆分通過(guò)服務(wù)器收到的響應(yīng),以便我可以取值,并在文本上設(shè)置。但我不能采取這些值...響應(yīng) : {“status”:“no”,“requestCount”:“0”,“estelamCount”:“0”}                    String[] split_model = response.split(",");                  //  Log.i("split_model",split_model);                    Log.i("phoneName", split_model[0]);日志 == > I/電話名稱(chēng): {“狀態(tài)”:“否”
查看完整描述

3 回答

?
交互式愛(ài)情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

       String status ="";


        JSONObject jsonObject = new JSONObject(response); //convert to json


        if (jsonObject.has("status")){ //check if has the key

            status = jsonObject.getString("status"); // get the value

        }else{


        }


        Log.d("TAG", status); // do sth with the value


        //Log => status


查看完整回答
反對(duì) 回復(fù) 2022-09-14
?
慕神8447489

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊

您從服務(wù)器接收 json 數(shù)據(jù),因此您可以將其解析為 json,如前面的答案所示。更好的是,您可以使用Gson庫(kù)按如下方式解析數(shù)據(jù),1-創(chuàng)建一個(gè)表示您的存儲(chǔ)庫(kù)的類(lèi),您可以使用 http://www.jsonschema2pojo.org/ 之類(lèi)的工具來(lái)實(shí)現(xiàn)此目的,只需粘貼您的json字符串,然后從右側(cè)的選項(xiàng)中選擇Java作為目標(biāo)語(yǔ)言,Json作為源類(lèi)型,Gson作為注釋樣式, 并輸入要使用的任何類(lèi)名,結(jié)果應(yīng)類(lèi)似于此包 com.example;


import com.google.gson.annotations.Expose;

import com.google.gson.annotations.SerializedName;


public class Response {


@SerializedName("status")

@Expose

public String status;

@SerializedName("requestCount")

@Expose

public String requestCount;

@SerializedName("estelamCount")

@Expose

public String estelamCount;

}

然后,當(dāng)您想要處理結(jié)果時(shí),可以按以下步驟操作


Gson gson = new Gson();

//now you can parse the response string you received, here is responseString

Response response = gson.fromJson(responseString, Response.class);

//now you can access any field using the response object 

Log.d("Reponse" , "status =  " + response.status  + ", requestCount = " + response.requestCount + ", estelamCount = " + response.estelamCount ; 


查看完整回答
反對(duì) 回復(fù) 2022-09-14
?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

我想你是在問(wèn)解析你的回答,這就是你的做法


JSONObject myJson = new JSONObject(response);


String status = myJson.optString("status");

String count = myJson.optString("requestCount");

String estelamCount = myJson.optString("estelamCount");


查看完整回答
反對(duì) 回復(fù) 2022-09-14
  • 3 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)