Java: how to remove quotation marks from the JSON key using regular expressions
•
Java
I need to remove double quotes (objects with sub objects and arrays in the hierarchy) from the complex JSON structure I write it in Java (the application will run on Android)
I already have the string generated from JSON lib (gson). Instead of deserializing it back to an object, I try to use a regular expression to remove the double quotation marks, and then serialize it without the double quotation marks in the key name
I can't find a suitable pattern to replace them
Example: Jason:
{ "key1":"value1","key2":"555f9ecd-2ced-42b7-b956-33e759bf8db1","key3":false,"key4_parent":{ "child_key5":"Android","id":"7ae2facc-cdb3-7ae2-facccdb3bb86","name":"danny","bypassed":false },"object1":{ "deviceType":"Android","base64val":"MENPSENJTFpZQzR3b1lvU1pQZTk=","name":"john" },"requiredLevel":"PUSH","level":"debug","status":1012,"description":"Authentication in progress","objects":[ { "deviceType":"Android",{ "deviceType":"Android","name":"john" } ] }
Expected production:
{ key1:"value1",key2:"555f9ecd-2ced-42b7-b956-33e759bf8db1",key3:false,key4_parent:{ child_key5:"Android",id:"7ae2facc-cdb3-7ae2-facccdb3bb86",name:"danny",bypassed:false },object1:{ deviceType:"Android",base64val:"MENPSENJTFpZQzR3b1lvU1pQZTk=",name:"john" },requiredLevel:"PUSH",level:"debug",status:1012,description:"Authentication in progress",objects:[ { deviceType:"Android",{ deviceType:"Android",name:"john" } ] }
I know the output is not a valid JSON It is designed for easy - to - Search logging purposes
Any help will be appreciated!
Solution
I will do:
>Find "([^"]) ": > replace $1:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码