How can we convert a JSON array to a list in java

How can we convert a JSON array to a list in java - Hello friend inabnomaniiyaha, In the article that you read this time with the title How can we convert a JSON array to a list in java, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel Code-java-example,what we write you can understand. Alright, happy reading.

Judul : How can we convert a JSON array to a list in java
link : How can we convert a JSON array to a list in java

Baca juga


How can we convert a JSON array to a list in java

Java-based library and it can be useful to convert Java objects to JSON and JSON to Java Object. A Jackson API is faster than other API, needs less memory area and is good for the large objects. We can convert a JSON array to a list using the ObjectMapper class. It has a useful method readValue() which takes a JSON string and converts it to the object class specified in the second argument.

import java.util.*;

import com.fasterxml.jackson.databind.*;

public class JSONArrayToListTest1 {

   public static void main(String args[]) {

      String jsonStr = "[\"INDIA\", \"AUSTRALIA\", \"ENGLAND\", \"SOUTH AFRICA\", \"WEST INDIES\"]";

      ObjectMapper objectMapper = new ObjectMapper();

      try {

         List<String> countries = objectMapper.readValue(jsonStr, List.class);

         System.out.println("The countries are:\n " + countries);

      } catch(Exception e) {

         e.printStackTrace();

      }

   }

}

Output

The countries are:

[INDIA, AUSTRALIA, ENGLAND, SOUTH AFRICA, WEST INDIES]



That's the articleHow can we convert a JSON array to a list in java

That's it for the article How can we convert a JSON array to a list in java this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleHow can we convert a JSON array to a list in java with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/05/how-can-we-convert-json-array-to-list.html

0 Response to "How can we convert a JSON array to a list in java"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...