我遇到这个麻烦了吗?
[
{
"username": "apap",
"status": "",
"log": "",
"email": "apap@gmail.com",
"lat": "",
"dob": "5-11-1986"
},
{
"username": "apapp",
"status": "",
"log": "",
"email": "apapp@gmail.com",
"lat": "",
"dob": "5-11-1986"
}
],
"returncode": "0"
}
解析数据时出错 org.json.JSONException: Value {"incircle": at response of type org.json.JSONObject cannot be convert to JSONArray
为了提取内圆数组值,我正在编写以下代码:
public class MainActivity extends Activity {
TextView username;
TextView email;
TextView dob;
TextView lat;
TextView log;
ListView listView;
ArrayList<HashMap<String,String>> jsonlist;
JsonAdapter objAdapter;
Context ctx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.listView);
jsonlist = new ArrayList<HashMap<String,String>>();
JSONObject json = JSONfunctions
.getJSONfromURL("http://www.railsboxtech.com/flirtalert/alluser.php");
try {
JSONArray flirt = json.getJSONArray("response");
Toast.makeText(MainActivity.this, "namr", Toast.LENGTH_LONG).show();
for (int i = 0; i < flirt.length(); i++) {
JSONObject ei = flirt.getJSONObject(i);
JSONArray eie = ei.getJSONArray("incircle");
for (int j = 0; j < eie.length(); j++) {
JSONObject e = eie.getJSONObject(j);
HashMap<String, String> map = new HashMap<String, String>();
map.put("User",e.getString("username"));
map.put("Email",e.getString("email"));
map.put("dob",e.getString("dob"));
map.put("lat",e.getString("lat"));
map.put("log",e.getString("log"));
jsonlist.add(map);
}
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, jsonlist, R.layout.user_list,
new String[] { "User", "Email","dob","lat","log"}, new int[] {
R.id.username, R.id.email, R.id.dob, R.id.lat, R.id.log});
listView.setAdapter(adapter);
listView.setTextFilterEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}