I'm struggling with the process of converting a string into a nested hash in JavaScript.
Here is the string I want to convert:
"{'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 aim to enable hash['btc_usd']['price'] to return 376.2.
How can this be achieved?
Despite trying the following code, it doesn't execute as expected:
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);