2016-05-16 10 views
-1

Kann mir jemand helfen, lat und lange als Variablen daraus zu extrahieren?Json Parsen zu Variablen

url  : http://something.com/rest/items/location1?type=json 
data : {} 

'url' Ausgang dieses Ergebnis

{"type":"LocationItem","name":"location1","state":"9.4702741,-76.5070072","link":"http://something/rest/items/location1"}, 
+1

In welcher Sprache parsen Sie den JSON? – Daryl

+0

Diese Variablen sind in Javascript –

Antwort

0

Es sieht aus wie es ist schon ein JSON-Objekt zurückgegeben wird - kein Parsing erforderlich. Sie müssten nur den Status auf ein Komma aufteilen und die zwei Lat/Long-Stücke erhalten. Beispiel:

var myOutput = {"type":"LocationItem","name":"location1","state":"9.4702741,-76.5070072","link":"http://something/rest/items/location1"}; 
var state = myOutput.state; 
var splitState = state.split(','); 
var latitude = splitState[0]; 
var longitude = splitState[1]; 
console.log("Latitude: " + latitude); 
console.log("Longitude: " + longitude); 
+0

vielen Dank, es funktioniert für mich. –