1
$.ajax({
url: '/GisMap/GetLayers?layerName=All',
type: "get",
dataType:"json" ,
success: function (data) {
alert('Data received: ');
var xmlDoc = data.result;
console.log(xmlDoc.layers.layer[0].name);
alert(xmlDoc.layers.layer[0].name);
Jsonデータはサーバーから送信されていますが、特定の名前属性値を読み取ることができません。これは私のJsonデータです。はjsonファイルのname属性を読み取ることができません
{"layers":{"layer":[{"name":"poly_landmarks","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/poly_landmarks.json"},{"name":"Img_Sample","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/Img_Sample.json"},{"name":"tasmania_cities","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/tasmania_cities.json"},{"name":"tasmania_roads","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/tasmania_roads.json"},{"name":"tasmania_state_boundaries","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/tasmania_state_boundaries.json"},{"name":"tasmania_water_bodies","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/tasmania_water_bodies.json"},{"name":"archsites","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/archsites.json"},{"name":"restricted","href":"http:\/\/localhost:8080\/geoserver\/rest\/layers\/restricted.json"}]}}
私はエラー捕捉されない例外TypeErrorを取得しています:火(jquery.js:3317)で [resolveWithなど] Object.fireWithで (:Object.success(48 map.js)で未定義 のプロパティ '層' を読み込めませんjquery.js:3447) at done(jquery.js:9272) at XMLHttpRequest(jquery.js:9514) –
Nitesh
data = JSON.parse(data); console.log(data.layers.layer [0] .name); – JYoThI