I use GSON to check for a string that is in JSON format:
String json="{'hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}";
Gson gson=new Gson();
Response resp = new Response();
RequestParameters para = null;
try{
para = gson.fromJson(json, RequestParameters.class);
}catch(Exception e){
System.out.println("invalid json format");
}
This is good, but when I remove the quotes as shown below, I removed from hashkey:
"{hashkey':{'calculatedHMAC':'f7b5addd27a221b216068cddb9abf1f06b3c0e1c','secretkey':'12345'},operation':'read','attributes':['name','id'],'otid':'12'}"
It still validates it as the correct JSONformat and throws no exceptions and is not going to the catch body. Any reason why this is so? How can i solve this?
RequestParameters class:
public class RequestParameters {
HashKey hashkey;
String operation;
int count;
int otid;
String[] attributes;
}
source
share