[Solved] Basic Gson Help [closed]

Here’s an example that matches the structure in the question. input.json contents: { “next”:”uri-to-next-page”, “previous”:”uri-to-previous-page”, “total”:12, “buy_on_site”:true, “resource_uri”:”uri-to-resource-1″, “resource”: { “publisher”: { “name”:”publisher name 1″, “resource_uri”:”uri-to-resource-2″ }, “book_images”: { “image_url”:”url-to-image”, “file_type”:”PNG”, “name”:”book-image-name” }, “author”: { “name”:”author-name”, “resource_uri”:”uri-to-resource-3″ } } } The code to deserialize it: import java.io.FileReader; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class … Read more

[Solved] How to parse get roles value from this json?

your pojo class should be like this.then it will work public class MyPojo { private String[] roles; public String[] getRoles () { return roles; } public void setRoles (String[] roles) { this.roles = roles; } @Override public String toString() { return “ClassPojo [roles = “+roles+”]”; } } 1 solved How to parse get roles value … Read more

[Solved] Unable to parse this kind of string to java [closed]

This is basically a json stirng. Check more about it here: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition – December … Read more

[Solved] Can I parse my JSON data like this?

As you create an empty map, if you attempt to read “createdDate” you will get null as a result. This won’t throw any exception. However, in the next line you want to initialize a new Date object and pass dob1 (which is still always null). This will cause an IllegalArgumentException to be thrown. You could … Read more

[Solved] Parse JSON objects(lat and lng) in GoogleMap as markers

Please have a look at this line: for(Shop shop : this.response.shops){ map.addMarker(new MarkerOptions().position(new LatLng(shop.getShopLat(), shop.getShopLng())).title(shop.getShopAddress())); } In this line you want to create a new LatLng() object by adding into constructor an array instead of one value, change this line into: for(Shop shop : this.response.shops){ //remember to check is shop.getShopLat() is not null etc.. for(int … Read more

[Solved] Complex JSON to Java class

Use a JSON beautifier (like http://jsonformatter.curiousconcept.com/) so you can see better what’s in there. Then, create classes, like this: class article { String publish_date; String title; … 0 solved Complex JSON to Java class

[Solved] Appending semicolon to each item in array and comma to set of array objects, to form a string

I solved the problem. Code: public static void main(String[] args) { String jsonArray = “{\”payments\”:[{\”a\”:\”11\”,\”b\”:\”21\”,\”c\”:\”34\”,\”d\”:\”0\”},{\”a\”:\”54\”,\”b\”:\”66\”,\”c\”:\”21\”,\”d\”:\”76\”},{\”a\”:\”34\”,\”b\”:\”23\”,\”c\”:\”43\”,\”d\”:\”88\”}]}”; JsonObject jsonObject2 = new Gson().fromJson(jsonArray, JsonObject.class); JsonObject innerObj = new JsonObject(); StringBuilder joinBuilder = new StringBuilder(); Map<String, String> testMap = new LinkedHashMap<String, String>(); JsonArray paymentsArray = jsonObject2.getAsJsonArray(“payments”); for (JsonElement jsonElement : paymentsArray) { Set<Entry<String, JsonElement>> elemEntry = ((JsonObject) jsonElement).entrySet(); Iterator<Entry<String, … Read more

[Solved] complex json to java object conversion using gson

You need a class structure like this (pseudo-code): class Response String id DataList posts class DataList List<Data> data class Data String message From from String id String created_time DataList comments class From String name String id Note that you can change class names if you want, but you have to keep the attribute names to … Read more

[Solved] How to search for values inside Json file

how about using ObjectMapper final String json = “{\”yourjson\”: \”here\”, \”andHere\”: … }”; final ObjectNode node = new ObjectMapper().readValue(json, ObjectNode.class); if (node.has(“ID”)) { System.out.println(“ID: ” + node.get(“ID”)); } This is one of the many ways: Adding for GSON, String json = “your json here” // you can also read from file etc Gson gson = … Read more