0

When i log my namevaluepair i get this in my console.

01-07 13:51:55.137: I/System.out(723): URL:[data={"id":"69403","timestamp":"07-01-2013 13:51:55","longitude":"-122.084095","latitude":"37.422005"}]

But i need to delete the [ and ]. Does anybody know how to do this?

Here's the android code that does this.

json = new JSONObject(); 
        try { 

            json.put("longitude", longi); 

            json.put("latitude", lat); 
            json.put("timestamp", time); 

            json.put("id", "69403"); 


        } catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
        } 

        /// create StringEntity with current json obejct 

        try { 
      //  StringEntity se = new StringEntity(json.toString()); 

            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("data", json.toString()));
            httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            System.out.println("URL:" + httpost);
            System.out.println("URL:" + nvps);


            System.out.println("send about to do post");
            try {
                response = httpclient.execute(httpost);
                System.out.println("URL:" + httpost);

            } catch (ClientProtocolException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            } catch (IOException e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
David Raijmakers
  • 1,369
  • 1
  • 16
  • 40

2 Answers2

2

post your jsonObject without using BasicNameValuePair as:

 StringEntity se = new StringEntity(json.toString()); 
 se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
 httppost.setEntity(se); 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
0

work around code:

use substring like this to your output

your ouput

URL:[data={"id":"69403","timestamp":"07-01-2013 13:51:55","longitude":"-122.084095","latitude":"37.422005"}]

do like this, the starting 6 words ll get deleted or removed

String op = yourOutputString.substring(6)
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121