I am using volley for json parsing. I want to send some data using POST to server side. I am trying to send .Now can any one tell me that how can i send filter array to server?
Following is my snippet code. i tried also Hashmap
and Jsonobject
. but getting this error.
Error :
org.json.JSONException: Value at Data of type java.lang.String cannot be converted to JSONObject
Format
{
"typeName": "MANUFACTURER",
"typeId": 22,
"cityId": 308,
"sortBy": "productname",
"sortOrder": "desc",
"filter":[
{
"filterId":101,
"typeName":"CAT_ID",
"filterId":102,
"typeName":"CAT_ID"
}
]
}
For Code Check pastie
Hope this helps you.
For more information on how to create json object check this link
Android JSONObject : add Array to the put method
EDIT:
In case of more data it is better to use Gson convertor
http://www.vogella.com/tutorials/JavaLibrary-Gson/article.html
Also for creating pojo classes use this
http://www.jsonschema2pojo.org/
If you are having a problem in calling the API then this will help you.
where jObject is the JSON data you want to send to the server.
Implementation will be similar for JSONArray. Instead of JsonObjectRequest use JsonArrayRequest and send jArray instead of jObject.
For creating json array just do a little tweak
And finally add json array as below
In your case you are converting Json array to string
Following three steps should make it work for old Volley libraries lacking this suport.
Prepare payload and post:
[If Needed] Add this constructor in Class- JsonArrayRequest in Volley package if not already there
}
[If Needed] Override this method if not yet implemented to support JSONArray response from server.
I used below code to post JSONArray to volley. You have to use JsonArrayRequest and pass the JSON Array directly without adding it to any JSONObject. Also keep in mind to Override the "parseNetworkResponse" method to convert the response to JSONArray again as The ResponseListner for JsonArrayRequest expects a type of JSONArray
pass JSONObject to make request. use this https://www.androidhive.info/2014/09/android-json-parsing-using-volley/
Hi Volley does not support JsonArray request better use some other libraries...