【发布时间】:2016-08-30 06:10:36
【问题描述】:
这是我现在使用的代码:
try {
JSONObject root = new JSONObject(s);
//JSONObject userdata = root.getJSONObject("userdata");
JSONArray userdata = root.optJSONArray("userdata");
for(int i=0; i < userdata.length(); i++){
JSONObject jsonObject = userdata.getJSONObject(i);
NAME = jsonObject.getString("name");
EMAIL = jsonObject.getString("email");
PASSWORD = jsonObject.getString("password");
//data += "Node"+i+" : \n NAME= "+ NAME +" \n EMAIL= "+ EMAIL +" \n PASSWORD= "+ PASSWORD +" \n ";
}
}
【问题讨论】:
-
你能发布你的 Json 响应吗?
-
您的代码或 JSON 有问题。对不起,我不能在霍格沃茨以外使用魔法,所以你必须发布更多细节,比如
s字符串的内容,以及究竟是什么 -
感谢大家的回复。这是我的 JSON:-> {"userdata":[]}
-
class BackGround extends AsyncTask
{ @Override protected String doInBackground(String... params) { String name = params[0];字符串密码 = 参数 [1];字符串数据="";诠释时间; -
试试 { URL url = new URL("http://*****/laravel5.1/blog/public/showusers");字符串 urlParams = "name="+name+"&password="+password; HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoOutput(true); OutputStream os = httpURLConnection.getOutputStream(); os.write(urlParams.getBytes()); os.flush(); os.close(); InputStream = httpURLConnection.getInputStream(); while((tmp=is.read())!=-1){ 数据+= (char)tmp; } is.close(); httpURLConnection.disconnect();返回数据; }
标签: javascript java android json