Unable to parse json response from report_trouble

Issue #3 new
Sam Haddad repo owner created an issue

Report Trouble Log : Error parsing data org.json.JSONException: Value OK at status of type java.lang.String cannot be converted to JSONObject

Comments (1)

  1. cd34
        private void update_events() {
            EVENTS.clear();
            EVENTS.add("- Add new Event -");
            EVENTS.add("- Refresh Events -");
    
            SnapApplication app = ((SnapApplication)getApplicationContext());
            JSONArray events = app.get_Events();
            Log.e("PRE", events.toString());
            for (int loop=0;loop<events.length();loop++) {
                try {
                    JSONObject line = events.getJSONObject(loop);
                    EVENTS.add(line.getString("name"));
                } catch (JSONException e) {
                    e.printStackTrace();
                } 
            }
        }
    
    private String add_event(String event_name, String duration, String tags, String location_limit) {
     108                 String uri = "http://api.snapreplay.com/add_event";
     109                 
     110                 try {
     111                         SnapApplication app = ((SnapApplication)getApplicationContext());
     112                         Location location = app.get_location();
     113                         
     114                 JSONObject json_payload = new JSONObject();
     115                         json_payload.put("api_key", Constants.API_KEY);
     116                         json_payload.put("phone_id", app.getPhoneID());
     117                         json_payload.put("name", event_name.trim());
     118                         json_payload.put("duration", duration.trim());
     119                         json_payload.put("location_limit", location_limit.trim());
     120                         json_payload.put("hashtag", tags.trim());
     121                         json_payload.put("latlong", location.getLatitude() + ":" + location.getLongitude() );
     122                         
     123                 DefaultHttpClient httpclient = new DefaultHttpClient();
     124                 HttpPost httpost = new HttpPost(uri);
     125                 StringEntity se = new StringEntity(json_payload.toString(), "UTF-8");
     126 
     127                 httpost.setEntity(se);
     128                         httpost.setHeader("Accept", "application/json");
     129                         httpost.setHeader("Content-type", "application/json;charset=utf8");
     130 
     131                         HttpResponse response;
     132                         BufferedReader rd;
     133                         response = httpclient.execute(httpost);
     134                         rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
     135                         JSONObject json_r = new JSONObject( rd.readLine() );                    
     136                         
     137                         app.set_EventAuthToken(json_r.getString("id"));
     138                     app.set_EventTitle(json_r.getString("name"));
     139                     app.expire_Events();
     140                 } catch (Exception e) {
     141                         e.printStackTrace();
     142                 }
     143                 
     144                 return EVENT_ADDED;
     145     }
    
  2. Log in to comment