How to decode some JSON into PHP -
i have following json output file. how extract "last" "sll" php variable?
{ "usd" : {"15m" : 93.89699, "last" : 93.89699, "buy" : 93.25001, "sell" : 93.89698, "24h" : 84.3, "symbol" : "$"}, "cny" : {"15m" : 573.0, "last" : 573.0, "buy" : 563.76252, "sell" : 588.11678, "24h" : 572.65, "symbol" : "¥"}, "jpy" : {"15m" : 9100.0, "last" : 9100.0, "buy" : 9100.0, "sell" : 9150.0, "24h" : 8240.81, "symbol" : "¥"}, "sgd" : {"15m" : 115.20412, "last" : 115.20412, "buy" : 112.64417, "sell" : 117.51034, "sll" : {"15m" : 23207.99, "last" : 23207.99, "buy" : 23207.99, "sell" : 23207.99, "24h" : 23207.99, "symbol" : "l$"}, }
at first json have irregularities:
wrong json:
{ "usd" : {"15m" : 93.89699, "last" : 93.89699, "buy" : 93.25001, "sell" : 93.89698, "24h" : 84.3, "symbol" : "$"}, "cny" : {"15m" : 573.0, "last" : 573.0, "buy" : 563.76252, "sell" : 588.11678, "24h" : 572.65, "symbol" : "¥"}, "jpy" : {"15m" : 9100.0, "last" : 9100.0, "buy" : 9100.0, "sell" : 9150.0, "24h" : 8240.81, "symbol" : "¥"}, "sgd" : {"15m" : 115.20412, "last" : 115.20412, "buy" : 112.64417, "sell" : 117.51034, "sll" : {"15m" : 23207.99, "last" : 23207.99, "buy" : 23207.99, "sell" : 23207.99, "24h" : 23207.99, "symbol" : "l$"}, }
right json:
{ "usd":{"15m":93.89699,"last":93.89699,"buy":93.25001,"sell":93.89698,"24h":84.3,"symbol":"$"}, "cny":{"15m":573,"last":573,"buy":563.76252,"sell":588.11678,"24h":572.65,"symbol":"\u00a5"}, "jpy":{"15m":9100,"last":9100,"buy":9100,"sell":9150,"24h":8240.81,"symbol":"\u00a5"}, "sgd":{"15m":115.20412,"last":115.20412,"buy":112.64417,"sell":117.51034}, "sll":{"15m":23207.99,"last":23207.99,"buy":23207.99,"sell":23207.99,"24h":23207.99,"symbol":"l$"} }
}
for take last element of sll node:
$arr = json_decode($json,1); end($arr["sll"]);
Comments
Post a Comment