import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.parser.ParseException;
import org.json.simple.parser.JSONParser;
/****
How to decode Json
JSON >> [0,{"signedPdfBase64":"JVBERi0xLjUKJeLjz9M=="}]
*****/
public class JsonDecode {
public static void main(String[] args){
JSONParser parser = new JSONParser();
String jsonMaked = "[0,{\"signedPdfBase64\":\"JVBERi0xLjUKJeLjz9M==\"}]";
System.out.println("****** JSON is *******");
System.out.println(jsonMaked);
System.out.println(jsonMaked);
try{
Object obj1 = parser.parse(jsonMaked);
JSONArray array = (JSONArray)obj1;
System.out.println("\n******** Get 2nd element of array *******");
System.out.println(array.get(1));
JSONObject obj2 = (JSONObject)array.get(1);
System.out.println("\n******** After decode JSON is *********");
System.out.println(obj2.get("signedPdfBase64"));
}catch(ParseException pe){
System.out.println("position: " + pe.getPosition());
System.out.println(pe);
}
}
}
No comments:
Post a Comment