我需要发送请求,但是在字符串上
url = "http://some-site.com/api/?photos.getPhotosByCategory={"id":"1","limitOne":"3","limitTwo":"3"}";
我有Syntax error on tokens, delete these tokens
,问题在于引号...请告诉我,我该如何解决?
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();
}
答案 0 :(得分:0)
好吧,只需替换你的“by”:
url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";
你可以自己想出来......
答案 1 :(得分:0)
逃避你的报价。请尝试下面的代码
String url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";
答案 2 :(得分:0)
如果您在字符串中遇到问题
url = "http://some-site.com/api/?photos.getPhotosByCategory=`{"id":"1","limitOne":"3","limitTwo":"3"}";`
换到
url = "http://some-site.com/api/?photos.getPhotosByCategory={\"id\":\"1\",\"limitOne\":\"3\",\"limitTwo\":\"3\"}";
如果在服务器上发送此JSON时遇到问题,请使用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