Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

java - JSON parsing problem

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 me error 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();
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...