Reputation: 1921
I am facing this error while I am posting a json array to server using retrofit. My json is valid as I checked the same by an online tool
Here is my json that I am posting
[
{
"image":"/9j/4AAQ//Z",
"pole_code":"Adv234",
"latitude":28.62628851,
"longitude":77.37868293,
"vendor_name":"1"
}
]
And the here is the method for posting the same
@POST("SyncPole")
Call<SyncApiResponse>uploadSurveyData(@Body JsonArray array);
Code for making JsonArray
private JsonArray createJsonArray(List<PoleSurveyData> list){
JsonArray jsonArray = new JsonArray();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
JsonObject jsonObject = new JsonObject();
try {
String imgString = Base64.encodeToString(list.get(i).getImage(),
Base64.NO_WRAP);
jsonObject.addProperty("image", imgString);
jsonObject.addProperty("pole_code", list.get(i).getPoleCode());
jsonObject.addProperty("latitude", list.get(i).getLatitude());
jsonObject.addProperty("longitude", list.get(i).getLongitude());
jsonObject.addProperty("vendor_name","1");
jsonArray.add(jsonObject);
;
}catch (Exception e){
e.printStackTrace();
}
}
}
return jsonArray;
}
I have followed these links "Expected BEGIN_OBJECT but was STRING at line 1 column 1" but none of them is working
Screen shot of postman request
Can someone help me out where I am doing wrong
Upvotes: 0
Views: 944
Reputation: 3930
"success"
You are getting String
in Response
but you expecting an object
of SyncApiResponse
. that's the problem
Solution: you have to change the response format. like the following structure.
{
"status": "success",
"message": "demo message"
}
Upvotes: 1