A
A
Alexander2016-09-27 14:39:05
PHP
Alexander, 2016-09-27 14:39:05

Why does the bool(FALSE) JSON error occur?

I'm trying to learn how to work with JSON, but I don't understand why an error occurs ... Here's the cad:

$jsonString = '
{
  "payment_type": 1,
  "address": {
      "town_id": 1,
      "street": "Яузская аллея",
      "house_number": "2",
      "underground": null,
      "comment": "Яузская аллея, д. 21А",
      "house_frame": "",
      "flat_number": "",
      "house_building": ""
  }
}                               
';
$cart = json_encode($jsonString, TRUE);
print $cart->payment_type;
print var_dump($cart);

bool(false) - request error...
What's wrong? :)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Max, 2016-09-27
@SmoKE_xD

json_encode($jsonString, TRUE);
Well, you decode into an array, but you access it as an object

R
Rou1997, 2016-09-27
@Rou1997

print $cart['payment_type'];
And not town, but city.

A
Alexander, 2016-09-27
@SmoKE_xD

Thanks to everyone for the answers :) Everything is much simpler :))))))
There was a different encoding!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question