What is the best way to convert a JSON code as this:
{
\"data\" :
{
\"field1\" : \"value1\",
\"field2\" : \"value2\"
}
}
Underscore-java library can convert json string to hash map. I am the maintainer of the project.
Code example:
import com.github.underscore.lodash.U;
import java.util.*;
public class Main {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
String json = "{"
+ " \"data\" :"
+ " {"
+ " \"field1\" : \"value1\","
+ " \"field2\" : \"value2\""
+ " }"
+ "}";
Map data = (Map) U.get((Map) U.fromJson(json), "data");
System.out.println(data);
// {field1=value1, field2=value2}
}
}