June
June

Reputation: 139

multilevel json reading in jquery

{
      "result": {
        {
          "bitfinex:bfxbtc": {
            "price": {
              "last": 0.00067133,
              "high": 0.0006886,
              "low": 0.00066753,
              "change": {
                "percentage": -0.02351996,
                "absolute": -1.6169972e-05
              }
            },
            "volume":84041.625
          },
          "bitfinex:bfxusd": {
            ...
          },
          "bitfinex:btcusd": {
            ...
          },
          ...
        }
      }
    }

I'm able to parse data until result console.log(d.result.bitfinex:bfxbtc); but not able to read after writing bitfinex:btcusd its giving me error

Uncaught SyntaxError: missing ) after argument list

Do I need to use recursion?

Upvotes: 0

Views: 32

Answers (1)

Yaseen Ahmad
Yaseen Ahmad

Reputation: 1795

your json format is invalid please first format it and then use it like this.

var a = { "result": {
        "bitfinex:bfxbtc": {
          "price": {
            "last": 0.00067133,
            "high": 0.0006886,
            "low": 0.00066753,
            "change": {
              "percentage": -0.02351996,
              "absolute": -1.6169972e-05
            }
          },
          "volume": 84041.625
        },
        "bitfinex:bfxusd": {
          
        },
        "bitfinex:btcusd": {
          
        },
        
      }
    };
    document.getElementById('show').innerHTML = a.result["bitfinex:bfxbtc"].price.last;
    
<div id="show"></div>

when I try to validate your json get this error:

Error: Parse error on line 2: { "result": { { "bitfinex:bfxbt ---------------^ Expecting 'STRING', '}', got '{'

Upvotes: 1

Related Questions