0

I need to send request, but on string url = "http://some-site.com/api/?photos.getPhotosByCategory={"id":"1","limitOne":"3","limitTwo":"3"}"; I ve got Syntax error on tokens, delete these tokens, the problem is in quotes...Tell me please, how I can fix it ?

    url = "http://some-site.com/api/?photos.getPhotosByCategory={"id":"1","limitOne":"3","limitTwo":"3"}";
    new Thread(new Runnable() { 
        public void run(){

            HttpParams myParams = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(myParams, 10000);
            HttpConnectionParams.setSoTimeout(myParams, 10000);
            HttpClient httpclient = new DefaultHttpClient();

            String json=obj.toString();

            try {

                httppost = new HttpPost(url.toString());
                httppost.setHeader("Content-type", "application/json");

                StringEntity se = new StringEntity(obj.toString()); 
                se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                httppost.setEntity(se); 

                HttpResponse response = httpclient.execute(httppost);
                String temp = EntityUtils.toString(response.getEntity());
                Log.i("tag", temp);


            } catch (ClientProtocolException e) {

            } catch (IOException e) {
            }

                        tw = (TextView)findViewById(R.id.textView1);

                        tw.setText( response.toString());

            tw.post(new Runnable() {
                public void run() {
                    tw = (TextView)findViewById(R.id.textView1);
                    tw.setText( response.toString());
                }
            });

        }
}).start();

}
Nikos Leonov
  • 11
  • 1
  • 4

3 Answers3

0

Well, just replace your " by \" :

url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";

You could have figured this out by yourself...

Orabîg
  • 11,718
  • 6
  • 38
  • 58
0

Escape your quote. Try below code

String url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";
Rais Alam
  • 6,970
  • 12
  • 53
  • 84
0

If you have problem in string

url = "http://some-site.com/api/?photos.getPhotosByCategory=`{"id":"1","limitOne":"3","limitTwo":"3"}";`

swap to

url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";

If you have a problem when you send this JSON on server, use unicode

http://some-site.com/api/?photos.getPhotosByCategory=%7B%22id%22%3A%221%22%2C%22limitOne%22%3A%223%22%2C%22limitTwo%22%3A%223%22%7D
QArea
  • 4,955
  • 1
  • 12
  • 22