[英]How to get array in json using java?
請幫助我如何獲取xy的值,我已經嘗試過以下代碼,但無法正常工作。 我的下面的代碼錯誤嗎? 請幫我。 提前致謝
下面的Json示例
{"name":"room ko","lights":["3","2"],"type":"Room","state":{"all_on":true,"any_on":true},"recycle":false,"class":"Living room","action":{"on":true,"bri":254,"hue":34704,"sat":198,"effect":"none","xy":[0.3228,0.3291],"ct":167,"alert":"none","colormode":"xy"}
到目前為止,我在這里嘗試過的代碼。
String message="";
JSONArray jsonArray = null;
try {
JSONObject jsonObject = new JSONObject(s);
message = jsonObject.getString("name");
jsonArray = jsonObject.getJSONArray("xy");
Log.d(TAG,jsonArray);//error in here
} catch (JSONException e) {
e.printStackTrace();
}
我想你想:
jsonArray = jsonObject.getJSONObject("action").getJSONArray("xy");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.