Mobile app version of vmapp.org
Login or Join
Smith883

: Extracting from JSON REST API I would like to know how to extract particular field of data from the REST API. I would like to get the "bits-per-second-tx" data, only and I have tried http://localhost/net/json?field=bits-

@Smith883

Posted in: #Api #Html #Php #Restful

I would like to know how to extract particular field of data from the REST API.

I would like to get the "bits-per-second-tx" data, only and I have tried
localhost/net/json?field=bits-per-second-rx http://localhost/net/json?$select=bits-per-second-rx


However, it is still given me all the information.

The main reason for extraction information is that I am trying to plot a graph based on the "bits-per-second-rx" data on the my web page. I am trying produce real-time graph base on the "rx" on my web page. Is that possible?
I can parse the following data from the REST api using


"curl linK..../json | python -m json.tool"


[{"dpid":"00:00:00:00:00:00:00:03","port":"1","updated":"Tue Mar 28 03:08:46
PDT 2017","bits-per-second-rx":"60","bits-per-second-tx":"60"},
{"dpid":"00:00:00:00:00:00:00:01","port":"1","updated":"Tue Mar 28 03:08:46
PDT 2017","bits-per-second-rx":"60","bits-per-second-tx":"60"},
{"dpid":"00:00:00:00:00:00:00:02","port":"1","updated":"Tue Mar 28 03:08:46
PDT 2017","bits-per-second-rx":"0","bits-per-second-tx":"126"},
{"dpid":"00:00:00:00:00:00:00:04","port":"1","updated":"Tue Mar 28 03:08:46
PDT 2017","bits-per-second-rx":"60","bits-per-second-tx":"60"}]


I only want the information of "bits-per-second-rx", how should I achieve that?

Thank you.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Smith883

1 Comments

Sorted by latest first Latest Oldest Best

 

@Hamaas447

Thank you guys, after two days of research and try and errors.

I have finally found the solution, which might be easy for other people but I did stress out to get the solution.

<?php

$json_string = 'http://0.0.0.0:8080/wm/statistics/bandwidth/00:00:00:00:00:00:00:01/1/json';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata,true);
echo "<pre>";
print_r($obj);
echo "<br>---------------------------------<br>";
echo $obj[2]['bits-per-second-rx'];
echo "<br>---------------------------------<br>";
echo $obj[1]['bits-per-second-rx'];
echo "<br>---------------------------------<br>";
echo $obj[0]['bits-per-second-rx'];
?>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme