0
Comment obtenir une réponse json dans une variable javascript?Comment stocker la réponse json à une variable javascript et afficher
Ceci est mon fichier index.json.jbuilder
`json.array! @properties do |p|
json.id p.id
json.Space_name p.Space_name
json.address p.address
json.city p.city
json.state p.state
json.country p.country
json.latitude p.latitude
json.longitude p.longitude
end`
Maintenant, je reçois la réponse JSON comme celui-ci
[{"id":22,"Space_name":"mumbai","address":"mumbai","city":"sharjah","state":"fujairah","country":"United Arab Emirates","latitude":"19.0759837","longitude":"72.87765590000004"},{"id":2,"Space_name":"Bangalore","address":"Banglore","city":"abu-dhabi","state":"ajman","country":"United Arab Emirates","latitude":"37.2809455","longitude":"49.59241339999994"}
mais je besoin d'une sortie comme celui-ci (stocké dans une variable), pour par exemple:
properties= [{"id":22,"Space_name":"mumbai","address":"mumbai","city":"sharjah","state":"fujairah","country":"United Arab Emirates","latitude":"19.0759837","longitude":"72.87765590000004"},{"id":2,"Space_name":"Bangalore","address":"Banglore","city":"abu-dhabi","state":"ajman","country":"United Arab Emirates","latitude":"37.2809455","longitude":"49.59241339999994"}
J'utilise ici gem JBuilder pour JSON respose. Toute aide est appréciable.