R. Rio R. Rio - 6 months ago 15
PHP Question

Can't read a string of JSON

I have this JSON (is from Steam Market):


{"success":true,"lowest_price":"$5.79","volume":"2,932","median_price":"$5.79"}


And I have this code:

$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='.$name;
$market = json_decode(file_get_contents($urlm), true);
echo $market['lowest_price'];


But when I try it, they give me an error:


Notice: Undefined index: lowest_price


What is wrong? Because I have an other JSON with the same method and works perfect.

Answer

You should urlencode your varaiable:

$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='. urlencode($name);