I am having trouble converting a string to a hash (hash with nested hashes actually) in javascript.
I want to convert the following string:
"{'btc_usd': {'price': 376.2, 'volume': 42812.69, 'change': -0.5},'btc_cny': {'price': 2519.39, 'volume': 67148.51, 'change': -85.13},'ltc_usd': {'price': 3.068, 'volume': 4735.55, 'change': -0.58},'btc_ltc': {'price': 0.00805433, 'volume': 153.33, 'change': -0.76},'btc_eth': {'price': 0.00660196, 'volume': 6428.98, 'change': 5.87}}"
I want to make it so that I can do hash['btc_usd']['price'] and get 376.2.
How can I do this?
This is what I have tried but it doesn't seem to be running:
var string="{'btc_usd': {'price': 376.2, 'volume': 42812.69, 'change': -0.5},'btc_cny': {'price': 2519.39, 'volume': 67148.51, 'change': -85.13},'ltc_usd': {'price': 3.068, 'volume': 4735.55, 'change': -0.58},'btc_ltc': {'price': 0.00805433, 'volume': 153.33, 'change': -0.76},'btc_eth': {'price': 0.00660196, 'volume': 6428.98, 'change': 5.87}}"
var results=JSON.parse(string);
'should be double quotes"for it to be valid.