JSON配列をwebserviceに投稿していますが、解決できません。 以下のコードでは、 "str"はJSONArrayをstringに変換したものです。 JSONArrayはJSONObjectで構成され、各JSONObjectは3つのパラメータ(ID、Question、Answer)で構成されます。androidのWebサービスへのJSON配列の投稿
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("feedbackjson", str));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://172.16.10.64:8080/plugleadservices/rest/feedbackmanagement/feedbacknew");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams httpParameters = new BasicHttpParams();
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
//is = entity.getContent();
result = EntityUtils.toString(entity).toString();
} catch (Exception e)
{
Log.e("Loading Runnable Error in http connection :", e.toString());
}
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}
catch (Exception e)
{
Log.e("Loading Runnable Error converting result :", e.toString());
}
JSONObject json_data = new JSONObject(result);
System.out.println("#### Status Message : " +json_data.getString("statusMessage").toString());
System.out.println("#### Company ID : " +json_data.getInt("company_id"));
これは私が事前に
[
{
"fk_Company_id":4,
"q_Answer":"no",
"q_Name":"qwhgdfqw"
},
{
"fk_Company_id":2,
"q_Answer":"yes",
"q_Name":"sdfsdf"
},
{
"fk_Company_id":2,
"q_Answer":"yes",
"q_Name":"xcvfdgd"
},
{
"fk_Company_id":2,
"q_Answer":"no",
"q_Name":"xfgdf"
}]
感謝をWebServiceのためにJSONArrayの下に渡したい
05-06 14:50:48.459: W/System.err(8368): org.json.JSONException: End of input at character 0 of
05-06 14:50:48.459: W/System.err(8368): at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
05-06 14:50:48.459: W/System.err(8368): at org.json.JSONTokener.nextValue(JSONTokener.java:97)
05-06 14:50:48.459: W/System.err(8368): at org.json.JSONObject.<init>(JSONObject.java:156)
05-06 14:50:48.459: W/System.err(8368): at org.json.JSONObject.<init>(JSONObject.java:173)
05-06 14:50:48.459: W/System.err(8368): at com.plugleads.feedback.FeedBackQuestionsActivity.callWebservice(FeedBackQuestionsActivity.java:712)
05-06 14:50:48.459: W/System.err(8368): at com.plugleads.feedback.FeedBackQuestionsActivity.checkBoxes(FeedBackQuestionsActivity.java:371)
05-06 14:50:48.459: W/System.err(8368): at com.plugleads.feedback.FeedBackQuestionsActivity.isValidData(FeedBackQuestionsActivity.java:350)
05-06 14:50:48.459: W/System.err(8368): at com.plugleads.feedback.FeedBackQuestionsActivity$1.onClick(FeedBackQuestionsActivity.java:166)
05-06 14:50:48.459: W/System.err(8368): at android.view.View.performClick(View.java:4785)
05-06 14:50:48.459: W/System.err(8368): at android.view.View$PerformClick.run(View.java:19884)
05-06 14:50:48.460: W/System.err(8368): at android.os.Handler.handleCallback(Handler.java:739)
05-06 14:50:48.460: W/System.err(8368): at android.os.Handler.dispatchMessage(Handler.java:95)
05-06 14:50:48.460: W/System.err(8368): at android.os.Looper.loop(Looper.java:135)
05-06 14:50:48.460: W/System.err(8368): at android.app.ActivityThread.main(ActivityThread.java:5343)
05-06 14:50:48.460: W/System.err(8368): at java.lang.reflect.Method.invoke(Native Method)
05-06 14:50:48.460: W/System.err(8368): at java.lang.reflect.Method.invoke(Method.java:372)
05-06 14:50:48.460: W/System.err(8368): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
05-06 14:50:48.460: W/System.err(8368): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
を取得していますどのようなエラーです。
「FeedBackQuestionsActivity」の行番号は「712」ですか。 –
712 - JSONObject json_data =新しいJSONObject(結果);結果はnullです@ρяσѕρєяK – Naveen