org.json.JSONException:java.lang.String类型的值{" Reference":"" .."}无法转换为JSONArray [英] org.json.JSONException: Value {"Reference":"".."} of type java.lang.String cannot be converted to JSONArray

查看:109
本文介绍了org.json.JSONException:java.lang.String类型的值{" Reference":"" .."}无法转换为JSONArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,当我尝试从我的wcf服务解析到android时,它给了我一个错误。我的服务的回报是使用JSON。这是我的android代码:



DefaultHttpClient client = new DefaultHttpClient();

// http get request

HttpGet request = new HttpGet(http://192.168.1.125:8181/Managers/Authentification.svc/authen/?loga=+ t1.getText()。toString()+&pass =+ t2.getText( ).toString());



//设置hedear以获取JSON格式的数据

request.setHeader(Accept ,application / json);

request.setHeader(Content-type,application / json);



/ /得到回复

HttpResponse response = client.execute(request);

System.out.println(Connectee --->+ response.getAllHeaders() );



HttpEntity entity = response.getEntity();



//如果实体与长度相关0 ,表示系统中没有数据存在这些代码

if(entity.getContentLength()!= 0){

//流读者对象

Reader employeeReader = new InputStreamReader(response.getEntity()。getContent());

//创建一个缓冲区以便从阅读器填充它

char [] buffer = new char [(int)response.getEntity()。getContentLength()];

//在读者的帮助下填充缓冲区

employeeReader.read(buffer) ;

//关闭读者流

employeeReader.close();



//员工json对象

JSONObject tt = new JSONObject(new String(buffer));



System.out.println(.... .............. OK .........................);



System.out.println(参考:+ tt.getString(参考));

}

else {

System.out.println(...................不行............... .........);

}



}

catch(JSONException e ){

System.out.println(.. ................. ERRORJSON ........................);

e.printStackTrace();

} catch(例外e){

// TODO自动生成的捕获块

系统。通过out.println( ...................错误........................ );

e.printStackTrace();

}



}

});

Hi, my problem is that when i try to parse from my wcf service into android it gives me an error. the return for my service is with JSON. this is my android code:

DefaultHttpClient client = new DefaultHttpClient();
// http get request
HttpGet request = new HttpGet("http://192.168.1.125:8181/Managers/Authentification.svc/authen/?loga="+t1.getText().toString()+"&pass="+t2.getText().toString());

// set the hedear to get the data in JSON formate
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");

//get the response
HttpResponse response = client.execute(request);
System.out.println("Connectee--->" +response.getAllHeaders());

HttpEntity entity = response.getEntity();

//if entity contect lenght 0, means no data exist in the system with these code
if(entity.getContentLength() != 0) {
// stream reader object
Reader employeeReader = new InputStreamReader(response.getEntity().getContent());
//create a buffer to fill it from reader
char[] buffer = new char[(int) response.getEntity().getContentLength()];
//fill the buffer by the help of reader
employeeReader.read(buffer);
//close the reader streams
employeeReader.close();

//for the employee json object
JSONObject tt = new JSONObject(new String(buffer));

System.out.println("..................OK.........................");

System.out.println("Reference: " + tt.getString("Reference"));
}
else {
System.out.println("...................Not OK........................");
}

}
catch (JSONException e) {
System.out.println("...................ERRORJSON........................");
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("...................ERROR........................");
e.printStackTrace();
}

}
});

推荐答案

这篇关于org.json.JSONException:java.lang.String类型的值{" Reference":"" .."}无法转换为JSONArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆