{
who: 'troll_new3',
visibility: 'public',
poll: {
title: 'Favourite game?',
des_content_type: 'text',
description: 'I want to know which game you like!',
options_type: 'text',
comments_enabled: true,
poll_method: 'list',
}
}
受信するJSONObjectのフォーマットとしてこれが必要です。
これは私が実装しているコードです:
obj=new JSONObject();
try {
obj.put("options_type", "text");
obj.put("description", pd.getText().toString());
obj.put("des_content_type", "text");
obj.put("title", pt.getText().toString());
obj.put("comments_enabled", "false");
obj.put("poll_method",str);
} catch (JSONException e1) {
//TODO Auto-generated catch block
Log.v("my","error");
e1.printStackTrace();
}
obj1=new JSONObject();
try {
obj1.put("who", facebookId);
obj1.put("visiblity", "public");
obj1.put("poll", obj.toString());
} catch (JSONException e1) {
//TODO Auto-generated catch block
Log.v("my","error");
e1.printStackTrace();
}
StringEntity se=null;
try {
se = new StringEntity(obj1.toString());
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try{
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httppost.setEntity(se);
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-type", "application/json");
Log.v("myapp", "works till here. 2");
try {
HttpResponse response = httpclient.execute(httppost);
Log.v("myapp", "works till here. 3");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
事前定義されたJSON形式を出力で取得したい。{poll:'{"title": "dsfg"、 "des_content_type": "text"、 "poll_method": "list"、 "options_type": "text"、 " Comments_enabled ":" false "、" description ":" Dfg "}'、可視性:' public'、who:' 1758281246'}
誰か助けてください。