Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do you pick certain fields in json format in php
    text
    copied!<p>I calling a url which returns the data as json format. I like pick out some variables from this output. The ouput is as follows:</p> <pre><code>{ "graph_property" : [ { "name" : "calculation_method", "value" : "Geo Mean" }, { "name" : "graph_type", "value" : "TIME" } ], "measurement" : [ { "id" : "1132282", "alias" : "example.com" "bucket_data" : [ { "name" : "2013-JUN-20 11:23 AM", "id" : 1, "perf_data" : { "value" : "4.878", "unit" : "seconds" }, "avail_data" : { "value" : "100.00", "unit" : "percent" }, "data_count" : { "value" : "1", "unit" : "#" } }, { "name" : "2013-JUN-20 11:28 AM", "id" : 2, "perf_data" : { "value" : "-", "unit" : "seconds" }, "avail_data" : { "value" : "-", "unit" : "percent" }, "data_count" : { "value" : "-", "unit" : "#" } }, { "name" : "2013-JUN-20 11:33 AM", "id" : 3, "perf_data" : { "value" : "-", "unit" : "seconds" }, "avail_data" : { "value" : "-", "unit" : "percent" }, "data_count" : { "value" : "-", "unit" : "#" } } ], "graph_option" : [ { "name" : "perfwarning", "value" : "-", "unit" : "seconds" }, { "name" : "perfcritical", "value" : "-", "unit" : "seconds" }, { "name" : "availwarning", "value" : "-", "unit" : "percent" }, { "name" : "availcritical", "value" : "-", "unit" : "percent" }, { "name" : "bucketsize", "value" : "300", "unit" : "seconds" }, { "name" : "rows", "value" : "3", "unit" : "#" }, { "name" : "pagecomponent", "value" : "User Time", "unit" : "seconds" }, { "name" : "avg_perf", "value" : "4.878", "unit" : "seconds" }, { "name" : "avg_avail", "value" : "100.00", "unit" : "percent" }, { "name" : "total_datapoint_count", "value" : "1", "unit" : "#" }, { } ] } ], "link" : { "type" : "application/json", "href" : "http://api.keynote.com/", "rel" : "slotmetadata" } } </code></pre> <p>The values I am interested are these:</p> <pre><code> " name" : "2013-JUN-20 11:23 AM", "value" : "4.878", "name" : "2013-JUN-20 11:28 AM", "value" : "-", "name" : "2013-JUN-20 11:33 AM", "value" : "-", </code></pre> <p>The reason I am doing it this way is that sometimes, the web service call returns emtpy values. From this output, I like to pick the latest date that does not have an empty value and then print out the name and value which is not empty.</p> <p>Is there an easy way to pick the name and value field from this json output?</p> <p>when I do</p> <pre><code>$data&lt;-json_decode($resp) print_r($data) </code></pre> <p>one portion of the data is this:</p> <pre><code>[measurement] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 1132282 [alias] =&gt;example.com [bucket_data] =&gt; Array ( [0] =&gt; Array ( [name] =&gt; 2013-JUN-20 01:23 PM [id] =&gt; 1 [perf_data] =&gt; Array ( [value] =&gt; 3.074 [unit] =&gt; seconds ) [avail_data] =&gt; Array ( [value] =&gt; 100.00 [unit] =&gt; percent ) [data_count] =&gt; Array ( [value] =&gt; 1 [unit] =&gt; # ) ) [1] =&gt; Array ( [name] =&gt; 2013-JUN-20 01:28 PM [id] =&gt; 2 [perf_data] =&gt; Array ( [value] =&gt; 3.416 [unit] =&gt; seconds ) [avail_data] =&gt; Array ( [value] =&gt; 100.00 [unit] =&gt; percent ) [data_count] =&gt; Array ( [value] =&gt; 1 [unit] =&gt; # ) ) [2] =&gt; Array ( [name] =&gt; 2013-JUN-20 01:33 PM [id] =&gt; 3 [perf_data] =&gt; Array ( [value] =&gt; - [unit] =&gt; seconds ) [avail_data] =&gt; Array ( [value] =&gt; - [unit] =&gt; percent ) [data_count] =&gt; Array ( [value] =&gt; - [unit] =&gt; # ) ) ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload