I am getting Json array from mobile side and want to parse the Json in server side using Java and jersey and Gson. I am sending the JSON array in POST method from iOS. I want to consume the json but stuck on how do i save the json data in Java class. This is the structure of my Json array entities:{"stores":[{"tills":[{"name":"b1 till1"}],"name":"b1 store"},{"tills":[{"name":"b2 till2"}],"name":"b2 store"}],"name":"B mart"} entities:{"stores":[{"tills":[{"name":"c1 till1"}],"name":"c1 store"},{"tills":[{"name":"c2 till2"}],"name":"c2 store"}],"name":"C mart"} name:Dmart
I think you have to do simply like this: This is a code snippet i used in one of my test-applications
To parse JSON you need in my example the GSON-Library
@Path("/FriendsList")
public class RestWebServicesAPI{
@POST
@Path("/friends")
@Consumes(MediaType.APPLICATION_JSON)
public Friends saveFriendList(final String json){
Gson gs = new Gson();
Friends [] n = gs.fromJson(json, Friends [].class);
}
//ALTERNATIVE
@POST
@Path("/friends")
@Consumes(MediaType.APPLICATION_JSON)
public Friends saveFriendList(final Friends[] friends){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.