jeffery_the_wind
jeffery_the_wind

Reputation: 18188

jqgrid json data not working with json_decode

I have a json string that is posted to the server that looks like this:

{\"groupOp\":\"AND\",\"rules\":[{\"field\":\"screen_name\",\"op\":\"bw\",\"data\":\"aaa\"}]}

It looks pretty good to me, but the problem is the PHP function json_decode returns NULL. I made a codepad example that illustrates the problem here : http://codepad.org/SOJw9cZb. What do I have to do to this string to get json_decode to work properly?

This json string is sent to the server by the jqgrid Filter Toolbar module to identify the search parameters.

Thanks!

Upvotes: 0

Views: 282

Answers (1)

Robbie
Robbie

Reputation: 17710

var_dump(json_decode(str_replace('\"', '"', '{\"groupOp\":\"AND\",\"rules\":[{\"field\":\"screen_name\",\"op\":\"bw\",\"data\":\"aaa\"}]}')));

works just fine. i.e. convert the \" to "

Valid JSON is

{"groupOp":"AND","rules":[{"field":"screen_name","op":"bw","data":"aaa"}]}

Upvotes: 1

Related Questions