-2
Я отправляю некоторые данные в веб-службу, и я получаю ответ json, который я хочу передать jsonobject.Передача json ответа от webservice на переменные
Ответ веб-сервиса:
{
"ValidateLoginResult": [
{
"ErrorMessage": "Wrong username pass",
"PropertyName": null
}
]
}
и я хочу передать сообщение об ошибке и имя свойства для переменных. Я попытался с помощью JSONObject и JSONarray, но не имели никакой удачи
HttpClient httpclient = new DefaultHttpClient();
// 2. make POST request to the given URL
HttpPost httpPost = new HttpPost(serverURL);
StringEntity se = new StringEntity(data);
httpPost.setEntity(se);
// 7. Set some headers to inform server about the type of the content
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
// 8. Execute POST request to the given URL
HttpResponse httpResponse = httpclient.execute(httpPost);
// 9. Getting Reply
inputStream = httpResponse.getEntity().getContent();
...
...
JSONArray json = new JSONArray(convertInputStreamToString(inputStream));
JSONObject json_LL = json.getJSONObject(0);
String str_value=json_LL.getString("ErrorMessage");
показать свои усилия здесь. – Riser
Возможный дубликат [Как разобрать JSON в Java] (http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Selvin
Возможно, воспользуйтесь функцией «Дооснащение». Это сделает большую часть работы для вас. – iZBasit