json - Echo the STDIN given to a PHP script -


I'm trying to use PHP for a command line script. I pass a JSON string to it, and I'm trying to read the values, but when I echo $ user_inputs [ "foo"] , so why is this? Am I forgetting about json_decode, or is it about using STDIN?

my_test.php

  // Get Steediaian to $ Stdin = fopen ( 'php: // stdin', 'r'); // start user_inputs_json which will be full studine $ user_inputs_json = ""; // read all stdin while ($ line = fgets ($ stdin)) {$ user_inputs_json = $ line; } // Create the decoded Jason object. $ User_inputs = json_decode ($ user_inputs_json); // Try to resize a value This is where I get my error (written below). Echo $ user_inputs ["foo"]; Fclose ($ stdin);   

The Run it from the command line to pass JSON:

$ echo '{ "foo": " Hello world! "," Bar ":" Goodnight moon! "} '| Php my_test.php

I'm getting this error:

can not use the object Fatal error: Type stdClass in / users / Don / desktop / my_test.php row

default as if string json_decode converts the JSON PHP object you can use the second parameter if you want to get PHP array, json_decode:

  $ user_inputs_array = json_decode ($ user_inputs_json, true) ;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -