I have a json response like this
2019 May 28 10:03:56.586520 pacexg1v1 rdkbrowser2[4786]: 190528-10:03:56.586491 [mod=RDKBROWSER2, lvl=INFO] [tid=4786] onConsoleLog:rdkbrowser.cpp:926 [ConsoleAPI:144]: {"objectName":"com.comcast.BridgeObject_1","methodName":"JSMessageChanged","argv":["{\"action\":\"entitlementsAccountLink\",\"args\":{\"action\":\"appLaunch\",\"subscriptionEntitlements\":[{\"id\":\"Prime\",\"endDate\":1561629841000}]},\"pid\":7}"]}
From this using regex how can i get the json alone
{"objectName":"com.comcast.BridgeObject_1","methodName":"JSMessageChanged","argv":["{\"action\":\"entitlementsAccountLink\",\"args\":{\"action\":\"appLaunch\",\"subscriptionEntitlements\":[{\"id\":\"Prime\",\"endDate\":1561629841000}]},\"pid\":7}"]}
The following regular expression will do the work ({[\\s\\S]*})
when you have only one JSON data in a response and your response cannot contain {
and }
characters outside of the JSON data.
Otherwise you cannot resolve it with regular expressions, because a JSON data mostly contains recursion, ex. {"obj1": {"obj1_1": "val1_1"}}
.
If you have two JSON data in a response you cannot tell where the first one ends and where the second one begins with regular expression.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.