1
在執行下面的代碼我得到這個誤差org.json.JSONException:值在java.lang.String類型不能被轉換到JSONArray
org.json.JSONException: Value [{"value":"6","startDate":"1970-01-01T00:00:00","measureTypeId":1,"endDate":"1970-01-01T00:00:00","isTimeSet":true},{"value":"12","startDate":"1970-01-01T00:00:00","measureTypeId":1,"endDate":"1970-01-01T00:00:00","isTimeSet":true}] at measureTooteets of type java.lang.String cannot be converted to JSONArray
,
if (tweetType == TooteetType.MEASURE) {
measureJson = cursor.getString(cursor.getColumnIndex(MEASURE_JSON));
Log.d("ss","Measure json frm database______________"+measureJson);
if (measureJson != null) {
try {
JSONObject object = new JSONObject(measureJson);
// JSONArray jsonArray = object.getJSONArray("measureTooteets");
// new JSONObject("{your string}")
String notes = object.getString("measureTooteets");
JSONArray jsonArray = new JSONArray(notes);
mMeasure = new Measure(jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
其中度量(jsonArray)將訪問下面的代碼
public Measure(JSONArray jsonArray) {
try {
// JSONArray jsonArray = object.getJSONArray("MeasureTooteets");
for(int i =0; i<jsonArray.length(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
id = jsonObject.optString("id");
tooteetId = jsonObject.optString("tooteetId");
laneId = jsonObject.optString("laneId");
startDate = jsonObject.optString("startDate");
endDate = jsonObject.optString("endDate");
value = jsonObject.optDouble("value");
measureTypeId = jsonObject.optInt("measureTypeId");
isTimeSet = jsonObject.optBoolean("isTimeSet");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
請建議我任何想法來解決這個問題。這種說法
String notes = object.getString("measureTooteets");
JSONArray jsonArray = new JSONArray(notes);
: