Skip to content
WJunction - Webmaster Forum

How to get multiple values in array from json encoded string

Status
Not open for further replies.
How to get multiple values in array from json encoded string, for example :

PHP:
{"result":{"record":[{"Line":"1","raw":"; cPanel first:11.42.1.16 (update_time):1400591008 Cpanel::ZoneFile::VERSION:1.3 hostname:xxxx latest:11.42.1.16","ttl":"86400","type":":RAW"},{"Line":"2","raw":"; Zone file for xxxx","ttl":"86400","type":":RAW"},{"Line":"3","ttl":"14400","type":"$TTL"},{"name":"xxxx.in-addr.arpa.","Line":"4","Lines":"7","class":"IN","expire":"3600000","minimum":"86400","mname":"xxxx","refresh":"86400","retry":"7200","rname":"xxxx","serial":"2014052015","ttl":"86400","type":"SOA"},{"name":"xxxx.in-addr.arpa.","Line":"11","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"12","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"13","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"14","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"15","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"16","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"17","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"18","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"19","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"20","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"21","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"22","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"23","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"24","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"}],"status":"1","statusmsg":"Zone Serialized"}}

we trying to get all values like name, line, ptrdname,type etc in arrays so we that we can save in different strings like variable $name = all name values from this json string, $line = all line values from json string. or if any other better way we can use please let us know.

__________________
Added after 3 Hours 2 minutes:

its fixed now (myself). thanks.
 
Last edited:

5 comments

Try this code.
PHP:
<?php
$json = '{"result":{"record":[{"Line":"1","raw":"; cPanel first:11.42.1.16 (update_time):1400591008 Cpanel::ZoneFile::VERSION:1.3 hostname:xxxx latest:11.42.1.16","ttl":"86400","type":":RAW"},{"Line":"2","raw":"; Zone file for xxxx","ttl":"86400","type":":RAW"},{"Line":"3","ttl":"14400","type":"$TTL"},{"name":"xxxx.in-addr.arpa.","Line":"4","Lines":"7","class":"IN","expire":"3600000","minimum":"86400","mname":"xxxx","refresh":"86400","retry":"7200","rname":"xxxx","serial":"2014052015","ttl":"86400","type":"SOA"},{"name":"xxxx.in-addr.arpa.","Line":"11","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"12","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"13","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"14","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"15","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"16","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"17","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"18","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"19","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"20","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"21","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"22","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"23","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"24","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"}],"status":"1","statusmsg":"Zone Serialized"}}'  ;
$out = json_decode($json,true);
echo "<pre>";print_r($out);
?>
 
Try this code.
PHP:
<?php
$json = '{"result":{"record":[{"Line":"1","raw":"; cPanel first:11.42.1.16 (update_time):1400591008 Cpanel::ZoneFile::VERSION:1.3 hostname:xxxx latest:11.42.1.16","ttl":"86400","type":":RAW"},{"Line":"2","raw":"; Zone file for xxxx","ttl":"86400","type":":RAW"},{"Line":"3","ttl":"14400","type":"$TTL"},{"name":"xxxx.in-addr.arpa.","Line":"4","Lines":"7","class":"IN","expire":"3600000","minimum":"86400","mname":"xxxx","refresh":"86400","retry":"7200","rname":"xxxx","serial":"2014052015","ttl":"86400","type":"SOA"},{"name":"xxxx.in-addr.arpa.","Line":"11","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"12","class":"IN","nsdname":"xxxx","ttl":"86400","type":"NS"},{"name":"xxxx.in-addr.arpa.","Line":"13","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"14","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"15","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"16","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"17","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"18","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"19","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"20","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"21","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"22","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"23","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"},{"name":"xxxx.in-addr.arpa.","Line":"24","class":"IN","ptrdname":"xxxx","ttl":"14400","type":"PTR"}],"status":"1","statusmsg":"Zone Serialized"}}'  ;
$out = json_decode($json,true);
echo "<pre>";print_r($out);
?>

thanks brother, i already figured this out before, json encode & decode fixed my issue. thanks again.
 
How to get multiple values in array from json encoded string?

<?php

$fp
= fopen('php://stdin', 'r');
$json = @json_encode(array('a' => 'foo', 'b' => $fp));
var_dump($json);

?>
 
Status
Not open for further replies.

About the author

S
Active Member · Joined
.::. Affordable & Reliable IT Services .::.
929
Messages
71
Reactions
28
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom