I want to convert a string into JSON. JsonObject of java gson. The string is a nested JSON structure in which forward-slash () is added as you can see in name its has \\". ( One \ to escape \ and one \ for ".
How to ignore inner \ and convert into JSON object. I was trying with replaceAll to escapse \\" but did not work as it replaces \" also
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class Test {
public static void main(String args[]){
String json = "[{\"key\":\"px\",\"mKeyValues\":[{\"hmKey\":\"qx\",\"value\":\"[{\\\"name\\\":\\\"Test Equipment value\\\",\\\"status\\\":\\\"2\\\"}]\"}]}]";
JsonParser jsonParser = new JsonParser();
json = json.replaceAll("\\\\","");
System.out.println(json);
JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject();
System.out.println(jsonObject);
}
}
Actual Json is
[
{
"key": "px",
"mKeyValues": [
{
"hmKey": "qx",
"value": [
{
"name": "Test Equipment value",
"status": "2"
}
]
}
]
}
]