我有JSON值存儲主鍵值對中的主要& minor_id值,我得到的值是正確的,但是當我傳遞值來檢查它只檢查來自JSON的最後一個值,而不是檢查JSON中的所有值。我怎樣才能從值創建數組,並傳遞值的數組來檢查?從JSON值創建數組並通過
JSON:
[{"name":"Test","uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","major_id":"23695","minor_id":"46901","notification":"","type":"Image","product_image":"server.com/beacon/staging/images/product_images/visualize2.png"},
{"name":"Test1","uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","major_id":"42583","minor_id":"41770","notification":"","type":"Text","text_text":"<p>test</p>"}]
解析&分配:
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
//JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray jarray = new JSONArray(jsonStr);
for (int i = 0; i < jarray.length(); i++) {
jObject = jarray.getJSONObject(i);
Log.d("jsonObj_Response: ", "> " + jObject);
uuid = jObject.getString(TAG_UUID);
name = jObject.getString(TAG_NAME);
type = jObject.getString(TAG_TYPE);
//objFurnitureDesc.id = Integer.parseInt(jsonFurnitureDescObj.getString("id")) ;
major_id= Integer.parseInt(jObject.getString("major_id")) ;
minor_id= Integer.parseInt(jObject.getString("minor_id")) ;
region_server = new Region("region_server", uuid, major_id, minor_id); //creating region
public void onEnteredRegion(final Region region, List<Beacon> beacons) {
if (region.getIdentifier().equals("region_server")) {
notify_image.setVisibility(View.VISIBLE);
}
}
值:
,如果我有major_id & minor_id
major_id: 23695 minor_id=46901
major_id:42583 minor_id:41170
它檢查的42583 & 41170只
請格式化所以它的可讀性 – 2014-10-29 12:30:16
爲什麼downvote?......我越來越major_id從JSON傳遞到region_server檢查major_id是對還是錯如果是的話顯示圖像..但在這裏它只檢查最後的值..所以,我怎麼能創建數組並傳遞給region_server中的major_id字段? – 2014-10-29 12:35:10
你的問題不是很清楚,你的代碼格式不好。但我猜這可能是因爲語言障礙和/或你對這個網站有點新意。這是一個公平的問題。我會提出這個問題讓它有一點平衡。 – 2014-10-29 12:38:18