问题描述
我试图JSON解析在我的Android应用程序的链接是<一个href="https://www.buzzador.com/apps/$p$psent_software/webservice/index.php?op=ProductQ&campaign_id=607&userid=10776" rel="nofollow">https://www.buzzador.com/apps/$p$psent_software/webservice/index.php?op=ProductQ&campaign_id=607&userid=10776
当我把它变成JSON对象它给了错误,我错误是:08-31 14:40:52.281:WARN / System.err的(416):org.json.JSONException:java.lang.String类型的值不能转换为JSONObject的
公共静态字符串getmyproductquestiondetails(字符串userid,
串campaignid){// https://www.buzzador.com/apps/$p$psent_software/webservice/index.php?op=EducationResult&userid=1&questionid=1,2,3&answergivenbyuser=1,1,0
字符串数据= NULL;
尝试 {
网址URL =新的URL(
http://dignizant.com/buzz/webservice/index.php?op=getProductQuestion&userid=
+的userid +与&amp; campaign_id =+ campaignid);
如果(url.getProtocol()。与toLowerCase()。等于(https开头)){
trustAllHosts();
HttpsURLConnection HTTPS =(HttpsURLConnection)网址
.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
HTTP = HTTPS;
} 其他 {
HTTP =(HttpURLConnection类)url.openConnection();
}
}赶上(MalformedURLException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
utils的utils的=新utils的();
尝试 {
数据= utils.convertStreamToString(http.getInputStream());
的System.out.println(getproduct细节响应::+数据);
}赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
数据= e.toString();
}
返回的数据;
}
尝试 {
JSONObject的乔=新的JSONObject(响应);
}赶上(例外五){
// TODO:处理异常
e.printStackTrace();
}
的char [] UTF8 = NULL;
StringBuilder的properString =新的StringBuilder();
UTF8 = Response.toCharArray();
的for(int i = 0; I&LT; utf8.length;我++){
如果((int)的UTF8 [1] - ; 65000){
properString.append(UTF8 [I]);
}
}
的System.out.println(登录的响应::
+ properString.toString());
i am trying to Json parsing in my android app the link is https://www.buzzador.com/apps/present_software/webservice/index.php?op=ProductQ&campaign_id=607&userid=10776
when i put it into Json object it gives errors to meerror is :08-31 14:40:52.281: WARN/System.err(416): org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
public static String getmyproductquestiondetails(String userid,
String campaignid) {// https://www.buzzador.com/apps/present_software/webservice/index.php?op=EducationResult&userid=1&questionid=1,2,3&answergivenbyuser=1,1,0
String data = null;
try {
URL url = new URL(
"http://dignizant.com/buzz/webservice/index.php?op=getProductQuestion&userid="
+ userid + "&campaign_id=" + campaignid);
if (url.getProtocol().toLowerCase().equals("https")) {
trustAllHosts();
HttpsURLConnection https = (HttpsURLConnection) url
.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
http = https;
} else {
http = (HttpURLConnection) url.openConnection();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Utils utils = new Utils();
try {
data = utils.convertStreamToString(http.getInputStream());
System.out.println("getproduct details response :: " + data);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
data = e.toString();
}
return data;
}
try {
JSONObject jo = new JSONObject(response);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
char[] utf8 = null;
StringBuilder properString = new StringBuilder("");
utf8 = Response.toCharArray();
for (int i = 0; i < utf8.length; i++) {
if ((int) utf8[i] < 65000) {
properString.append(utf8[i]);
}
}
System.out.println("Response of Login::"
+ properString.toString());
这篇关于JSON解析问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!