0

I'm getting the following sample string through post parameter. I need to get the key value pair from the data to process further. I've used

json_decode($data)

But it throws an error. I copied the string into jsonlint and validated. The string is a valid json

{
    "724361997575090":"https:\/\/z-n.ak.fbcdn.net\/photos-h.ak\/hphotos-ak-xpf1\/v\/t1.0-0\/s130x130\/1904241_724361997575090_405663037_n.jpg?oh=6d847393648314f498b0ed5ddec339ca&oe=567A30F3&__gda__=1450240543_9f7147a5699bb9ce03747f5b9f4785f7",
    "10201722174609862":"https:\/\/z-n.ak.fbcdn.net\/photos-d.ak\/hphotos-ak-xpf1\/v\/t1.0-0\/s130x130\/996939_10201722174609862_1085044118_n.jpg?oh=43f8044e9b52940c8b6e8bcdf936b139&oe=567D8587&__gda__=1450242029_a3ffb1833c84aabafd50b947963016f4",
    "653561304732935":"https:\/\/z-1-scontent.xx.fbcdn.net\/hphotos-xfp1\/v\/t1.0-9\/s130x130\/10262274_653561304732935_4287650319995492122_n.jpg?oh=17d70cf9ec426d0f20070276d626e3ae&oe=567622FD",
    "785636858147560":"https:\/\/z-n.ak.fbcdn.net\/photos-g.ak\/hphotos-ak-xtf1\/v\/t1.0-0\/s130x130\/224598_785636858147560_1779521948992015329_n.jpg?oh=8ba4a34102ac9647d70631a2b3b07ef3&oe=5682CF08&__gda__=1450077117_42060c2c51c7dedffc2a12d67a09dddb",
    "10152196967129315":"https:\/\/z-1-scontent.xx.fbcdn.net\/hphotos-xft1\/v\/t1.0-9\/s130x130\/10364042_10152196967129315_4825955816401790627_n.jpg?oh=bac0bfcdc4caac23cdbcbf29d9b8e6cb&oe=565FDFA5",
    "504111853031524":"https:\/\/z-1-scontent.xx.fbcdn.net\/hphotos-xtf1\/v\/t1.0-9\/s130x130\/1514596_504111853031524_503900941_n.jpg?oh=fe73e70cfd85334374a1c50baabb738e&oe=567DAB84",
    "553468811388609":"https:\/\/z-n.ak.fbcdn.net\/sphotos-b.ak\/hphotos-ak-xpa1\/v\/t1.0-9\/s130x130\/935949_553468811388609_410272599_n.jpg?oh=5c6f5d197f01867b7991c2ed0ec5d33c&oe=566E137D&__gda__=1451227136_598cffb867c87e771f21b2ec6d591c2d"
}

Can someone help me on getting the key, value from the above sample?

Error:

Catchable fatal error: Object of class stdClass could not be converted to string
11
  • 3
    Don't you think the error could help ? Commented Sep 2, 2015 at 16:02
  • Post the error being thrown... Commented Sep 2, 2015 at 16:02
  • 1
    Also, please show where you assign the JSON to $data. I think you may have escaping issues. Commented Sep 2, 2015 at 16:04
  • 1
    You probably want $array = json_decode($data, true); and then do echo $array['553468811388609']; Commented Sep 2, 2015 at 16:06
  • 3
    Downvotes because "an error" is not the most helpful description of the problem. Commented Sep 2, 2015 at 16:08

1 Answer 1

1

Your issue is the second parameter of json_decode. If true, it will return an array, if false (by default) it will return a StdClass.

You should use the second parameter to true in your case.

Alternatively, you can embrace the fact that it returns an object and write : $object->553468811388609

Sign up to request clarification or add additional context in comments.

1 Comment

Maybe $object -> {'553468811388609'} ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.