0

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-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 http://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.

1
  • You should use a JSON parser to parse it. Commented Mar 29, 2017 at 7:20

1 Answer 1

0

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']; 
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.