0
JSON:如何將嵌套JSON寫入HashMap <String,String>?
{
"deviceId": "AAAAAAA1",
"cardInfo": {
"pan": "123456789",
"psn": "00",
"cvv": "123",
"panExpiryDate": "2017-12-12"
},
"productType": "CREDIT",
"requestor": 1234,
"aid": "A0000000",
"aidVersion": 1,
"panSource": null,
"deviceLanguage": "en"
}
的Android代碼:
protected String doInBackground(Void... params) {
Bundle bundle=getIntent().getExtras();
final String newdata=bundle.getString("newdata");
try {
js=new JSONObject(newdata);
di=js.getString("deviceId");
} catch (JSONException e) {
e.printStackTrace();
}
postDataParams = new HashMap<String, String>();
postDataParams.put("deviceId",deviceID);
postDataParams.put("cardInfo.pan",card);
postDataParams.put("cardInfo.psn",Psn);
postDataParams.put("cardInfo.cvv",cvv);
postDataParams.put("cardInfo.panExpiryDate",panExpiryDate);
postDataParams.put("productType",productType);
postDataParams.put("requestor",requestor);
postDataParams.put("aid",aid);
postDataParams.put("aidVersion",aidVersion);
postDataParams.put("panSource",panSource);
postDataParams.put("deviceLanguage",deviceLanguage);
response = service.postServerData(path,postDataParams);
try {
json = new JSONObject(response);
System.out.println("success " + json.get("success"));
success = json.getInt("success");
} catch (JSONException e) {
e.printStackTrace();
}
return response;
}
在編寫這些代碼我沒有得到從URL中任何迴應。你能幫我解決我犯的錯誤嗎?
「給我一個完整的代碼」不會在這裏工作的#1,這是一個問題和答案的地方,而不是要求別人代碼爲你免費。請描述您的問題,添加您正在努力的相關代碼,並希望有人能夠提供幫助。 – Egor
你希望得到的'HashMap'的鍵是什麼格式?什麼對您發佈的代碼無效或不完整? – qxz
你需要帶有字符串對象類型的hasmap,並且在該hashmap中放置一個帶有密鑰cardInfo的json對象。 –