Unable to access JSON object properties

I get back from the server a JSON string like this:

[{"Title":"Windows","URL":"http:\/\/www.domain.com\/soft\/","Type":"out","Price":"140"}] 

I save it in a string variable, and I try to convert it to a JSON object as follows:

 var json = JSON.parse(string); 

after that I get an object that looks great:

 [Object] ->Price: "140" ->Title: "Windows" ->Type: "out" ->URL: "http:www.domain.com/soft/" ->__proto__: Object 

but when I try to connect to it using, for example, json.Price , I get undefined , any idea what I'm missing here?

+4
source share
1 answer

When you complete your content with [], you get an array with one object. Therefore, this should work:

 json[0].Price 

But you can also remove the brackets.

+14
source

Source: https://habr.com/ru/post/1369450/


All Articles