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

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

如何將 CustomerName 和 CustomerPhone 從我從 api 接收的字符串中分

如何將 CustomerName 和 CustomerPhone 從我從 api 接收的字符串中分

千萬(wàn)里不及你 2022-10-07 16:17:52
如何將 CustomerName 和 CustomerPhone 從我從 API 接收的字符串中分離出來(lái):{  "CustomerPhone":"0300",  "CustomerName":"Saleh",  "CustomerPassword":"84CYmCulToJXo5KncGwSZa81acb2vbHjZ2IgUveMyeU=",  "Salt":"Q/IoQURM1Cv05wbkJjuo3w=="}
查看完整描述

4 回答

?
開(kāi)滿天機(jī)

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

以下是完成它的非常簡(jiǎn)單的步驟,

第 1 步:轉(zhuǎn)到http://www.jsonschema2pojo.org/并粘貼您的 JSON,現(xiàn)在選擇選項(xiàng) Target language as Java、Source Type JSON 、Annotation Style GSON。然后按預(yù)覽按鈕,將模型復(fù)制到剪貼板。

第 2 步:現(xiàn)在在您的項(xiàng)目中添加 GSON 庫(kù)

第 3 步:使用名稱 CustomerData 或您想要的任何名稱創(chuàng)建模型類,然后從剪貼板粘貼代碼。

它看起來(lái)很像

public class CustomerData {


@SerializedName("CustomerPhone")

@Expose

private String customerPhone;

@SerializedName("CustomerName")

@Expose

private String customerName;

@SerializedName("CustomerPassword")

@Expose

private String customerPassword;

@SerializedName("Salt")

@Expose

private String salt;


public String getCustomerPhone() {

return customerPhone;

}


public void setCustomerPhone(String customerPhone) {

this.customerPhone = customerPhone;

}


public String getCustomerName() {

return customerName;

}


public void setCustomerName(String customerName) {

this.customerName = customerName;

}


public String getCustomerPassword() {

return customerPassword;

}


public void setCustomerPassword(String customerPassword) {

this.customerPassword = customerPassword;

}


public String getSalt() {

return salt;

}


public void setSalt(String salt) {

this.salt = salt;

}


}

第 4 步:現(xiàn)在您必須通過(guò)以下代碼將 JSON 解析為 GSON 對(duì)象,其中響應(yīng)變量將是您的 JSON 字符串。


CustomerData customerData = new Gson().fromJson(response,CustomerData.class);

customerData.getCustomerName();

customerData.getCustomerPhone();


查看完整回答
反對(duì) 回復(fù) 2022-10-07
?
吃雞游戲

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

嘗試這個(gè):


String jsonText = "{\"CustomerPhone\":\"0300\",\"CustomerName\":\"Saleh\",\"CustomerPassword\":\"84CYmCulToJXo5KncGwSZa81acb2vbHjZ2IgUveMyeU=\",\"Salt\":\"Q/IoQURM1Cv05wbkJjuo3w==\"}";

try {

    JSONObject jsonObj = new JSONObject(jsonText);

    String CustomerPhone = jsonObj.getString("CustomerPhone");

    String CustomerName = jsonObj.getString("CustomerName");

} catch (JSONException e){

    e.printStackTrace();

}


查看完整回答
反對(duì) 回復(fù) 2022-10-07
?
慕田峪7331174

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

對(duì)于您給定的字符串,下面的代碼可以正常工作,我已經(jīng)測(cè)試過(guò)了,它非常自我解釋。


    val jsonObject = JSONObject(jsonString)

    val phone = jsonObject.getString("CustomerPhone")

    val name = jsonObject.getString("CustomerName")

    val password = jsonObject.getString("CustomerPassword")

    val salt = jsonObject.getString("Salt")


    Log.d("phone", phone)

    Log.d("name", name)

    Log.d("password", password)

    Log.d("salt", salt)


查看完整回答
反對(duì) 回復(fù) 2022-10-07
?
MYYA

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

你有幾個(gè)選擇。

  1. 使用像 GSON 這樣的簡(jiǎn)單 JSON 庫(kù)并創(chuàng)建一個(gè)模型,您只需將字符串轉(zhuǎn)換為該模型即可

  2. 使用 Android JsonElements 并從字符串創(chuàng)建一個(gè) JsonElement 并按名稱遍歷每個(gè)孩子,直到獲得所需的孩子。

  3. 最丑陋的方式,但你可以做到,通過(guò)已知字符串解析字符串。(未經(jīng)測(cè)試,你必須調(diào)整這個(gè),但我真的希望你不要走這條路哈哈)

var customerStartPhoneIndex = jsonString.indexOf("CustomerPhone\":\")

var customerStartNameIndex = jsonString.indexOf("CustomerName\":\")

var customerEndphoneIndex = jsonString.indexOf(",")

var customerEndNameIndex = jsonString.indexOf(",", str.indexOf(",") + 1)

var customerPhone = jsonString.subString(customerStartPhoneIndex, customerEndPhoneIndex)

var customerName = jsonString.substring(customerStartNameIndex, customerEndNameIndex)


查看完整回答
反對(duì) 回復(fù) 2022-10-07
  • 4 回答
  • 0 關(guān)注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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