0

I want to read data in the javascript which is received from the server in JSON format.

I've been using this a lot, but now it seems that I hit the wall with this example:

JSON

{
    "results": [
        {
            "MIN(jtable.HIT_VALUE)": "70.200000",
            "AVG(jtable.HIT_VALUE)": "124.4077234969",
            "MAX(jtable.HIT_VALUE)": "1854.620000"
        }
    ]

}

JAVASCRIPT

How to read these values?

I have tried this

response.results[i].MIN(jtable.HIT_VALUE)

and I'm getting this error:

TypeError: Object #<Object> has no method 'MIN'

Any ideas?

Ahmad Adibzad
  • 501
  • 2
  • 6
  • 14
user123_456
  • 5,635
  • 26
  • 84
  • 140

3 Answers3

4

MIN(jtable.HIT_VALUE) is the key and has to be used as such using the square bracket notation like

response.results[i]['MIN(jtable.HIT_VALUE)']
shyam
  • 9,134
  • 4
  • 29
  • 44
1

Use it as string:

response.results[i]['MIN(jtable.HIT_VALUE)']
Rene Pot
  • 24,681
  • 7
  • 68
  • 92
1

JavaScript interprets the call response.results[i].MIN(jtable.HIT_VALUE) as an attempt to call a nonexistent function MIN.

Consider using this:

response.results[i]["MIN(jtable.HIT_VALUE)"]
potato25
  • 186
  • 5