wackou
wackou

Reputation: 13

Can't get data from json

I need to get brand: "hello world" When I send using post data with json and get it with

 $input = Input::all();

then with

die(print_r($input));

this is written

Array ([[], {brand: "hello world"}, [], 1427154586016])1

And

I tryed using json_encode and get with

die(print_r($encode));

this

{data: "{"brand":"Hello world"}", dc: "142715"}1

now if I do

$brand = $encode['data'] or $brand = $encode['brand']

I get an error. How do I get Hello world to var $brand

Upvotes: 0

Views: 63

Answers (1)

Andy
Andy

Reputation: 935

It looks like you're using json_encode() when you should be using json_decode(). But like kamlesh pointed out, it appears that your original JSON data is not valid JSON to begin with, so this would not help you. This wiki article has an example of valid syntax.

Also, if you're using laravel, you can use the helper function dd(), which will die() and var_dump() automatically for you, saving you a bit of time.

Hopefully this solves your problem, but if not, read the docs for the Input. There should be something there to get you on the right track.

Upvotes: 1

Related Questions