我有一個json字符串字符串,我想從中獲取值。它是密鑰對形式,所以我需要每個密鑰的值。如何從JSON中獲取值字符串
我試圖得到的值,但我沒有得到它。
JSON字符串是這樣的:
{
"document": {
"xmlns:xsi": "http:\/\/www.w3.org\/2001\/XMLSchema-instance",
"xsi:schemaLocation": "http:\/\/ocrsdk.com\/schema\/recognizeard-1.0.xsd http:\/\/ocrsdk.com\/schema\/recognized-1.0.xsd",
"xmlns": "http:\/\/ocrsdk.com\/schema\/recognize-1.0.xsd",
"businessCard": {
"imageRotation": "noRotation",
"field":
[{
"type": "Name",
"value": "Rafcev B. Agnrwal"
}, {
"type": "Company",
"value": "VJ>"
}, {
"type": "Text",
"value": "Dr. Rafcev B. Agnrwal\nMOB 0324%\nun\n) AOM*. founts. sso\nVJ>\nT"
}]
}
}
}
我想獲得 「姓名」, 「地址」, 「公司」 等的值
我試圖讓這樣的:
JSONArray array;
if(mIntent.getStringExtra("jsonString") != null) {
Log.d("json", mIntent.getStringExtra("jsonString"));
try {
JSONObject object = new JSONObject(mIntent.getStringExtra("jsonString"));
array = object.getJSONArray("field");
for (int i = 0; i < array.length(); i++) {
JSONObject subObject1 = array.getJSONObject(i);
edt_FirstName.setText(object.getString("Name"));
}
} catch (JSONException e) {
}
任何人都可以幫我嗎?謝謝。
編輯:
我試圖檢查這樣的價值觀:
for (int i = 0; i < array.length(); i++) {
JSONObject subObject1 = array.getJSONObject(0);
String type = subObject1.getString("type");
String value = subObject1.getString("value");
if (type.equals("Name")) {
edt_FirstName.setText(value);
}
if(type.equals("Address"))
{
edt_address.setText(value);
}
if(type.equals("Company"))
{
edt_company.setText(value);
}
if(type.equals("Mobile"))
{
edt_Mobile.setText(value);
}
}
我想從外地陣列中的所有值,並設置爲文本視圖,但我正在逐漸只有名稱值而不是其他值。
另外我可以像移動設備那樣獲得兩次移動字段,我可以獲得兩次,所以我想將兩個移動設備值合併並顯示出來。
以及如何從字段數組中獲取值? – Sid
@Sid更新的詳細信息 – manman
你能檢查編輯的問題嗎? – Sid