Я читаю строковые данные из SharedPreference
. Формат моей строки -
[{
"name": "sdf",
"phone": "2356235623",
"no_people": "2"
}]
Я хочу прочитать все JSONobjects
, присутствующие в этом JSONArray
. Поэтому я конвертирую эту строку в массив JSON как
String tempData = addqueuetemp.getString("tempdata", "");
JSONArray cacheTemp=new JSONArray(tempData);
Теперь я анализирую этот массив JSON как
JSONArray cacheTemp=new JSONArray(tempQueue);
for(int i=0;i<cacheTempQueue.length();i++){
JSONObject tempObject=cacheTemp.getJSONObject(i);
CurrentStatusEntry tempEntry=new CurrentStatusEntry();
tempEntry.setName(tempObject.getString("name");
current.add(tempEntry);
adapter = new QueueAdapter(current, getActivity().getApplicationContext());
recyclerView.setAdapter(adapter);
}
Но я получаю ошибку как
org.json.JSONException: Value {"name":"sdf","phone":"2356235623","no_people":"2"} at 0 of type java.lang.String cannot be converted to JSONObject
Как решить эту проблему?