I tried to decode and parse the string that an API returns, however the syntax of the returned JSON object is weird.
I could just strip elements from the string, but was wondering what is the best way to clean up this JSON string and convert it to a Ruby hash?
"DataCallBack([
{
\"detail1\": \"result1\",
\"detail2\": \"result2\",
\"Attr1\": [
{
\"detail1\": \"result1\",
\"detail2\": \"result2\",
},
{...}
]
],
\"Attr2\": [
{
\"detail1\": \"result1\",
\"detail2\": \"result2\",
},
{...}
]
}
])"
JSON.parse?JSON.parseordecodeI getJSON::ParserError: 795: unexpected token at 'DataCallBack...DataCallBackwrapper callback? JSONP is really only designed to work with javascript.callbackparameter and get raw JSON that you can directly parse. JSONP is simply a workaround that allows cross domain fetching of data in a browser.