JSONStringer giving null object in Android 2.1 (update)
I am making post call to a web service by sending object in JSON
format. I am using GSON
to convert my object to JSON
and JSONStringer
to create key-value pair to send to server in a post
call.
JSONStringer billString = new JSONStri开发者_开发知识库nger().object()
.key("details").value(new JSONObject(json));
CustomHttpRequest request = new CustomHttpRequest(WebserviceBaseAddress);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-type", "application/json");
request.AddParam("entity", billString.toString());
request.GetRequest(RequestMethod.POST);
This line of code works fine in Android 2.2, but 2.1, billString is null. That is why I am getting null exception for (request.AddParam("entity", billString.toString());
)
Can anybody tell me what is the problem here?
Or is there any way to make key-value pair to make post
call in GSON
, so that JSONStringer
can be removed?
Thanks Ashwani
Change
JSONStringer billString = new JSONStringer().object()
.key("details").value(new JSONObject(json));
to
String billString = new JSONStringer().object()
.key("details").value(new JSONObject(json)).endObject().toString();
The object syntax needs to be balanced -- there is a beginning and an ending.
精彩评论