无法读取 json 文件中的名称属性

尼特什
$.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 数据。

{"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"}]}}
约瑟

JSON.parse()

data = '{"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"}]}}';

  data = JSON.parse(data);

console.log(data.layers.layer[0].name);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法读取json文件

来自分类Dev

Ajax 读取 JSON - 无法读取未定义的属性“名称”

来自分类Dev

无法读取JavaScript中的json属性

来自分类Dev

无法从JSON文件读取数据

来自分类Dev

SWF文件无法读取json

来自分类Dev

无法在TemplateView中读取json

来自分类Dev

无法从Javascript中的json文件读取

来自分类Dev

未捕获的TypeError:无法读取属性JSON

来自分类Dev

为什么无法读取此 JSON 属性?

来自分类Dev

Android Studio无法读取json文件

来自分类Dev

php 读取 json 文件 - 我无法读取多层元素

来自分类Dev

JavaScript数组中的JSON导致错误无法读取属性

来自分类Dev

JavaScript数组中的JSON导致错误无法读取属性

来自分类Dev

无法读取JSON中父母的财产

来自分类Dev

无法读取Angular中的JSON响应

来自分类Dev

无法从Ruby中读取较大的json响应

来自分类Dev

从JsonContract读取JSON属性名称

来自分类Dev

jQuery跨域请求JSON:无法读取null的属性“ json”

来自分类Dev

Pyspark - 从 json 文件中获取属性名称

来自分类Dev

能够以 json 格式读取对象,但无法在 Angular2 中读取其属性

来自分类Dev

Ajax 在浏览器中读取和打印 JSON - 无法读取属性映射

来自分类Dev

Clojure的Cheshire JSON API无法读取整个JSON文件

来自分类Dev

d3.json无法从json文件读取多个对象

来自分类Dev

传递JSON作为道具-无法读取未定义的属性“名称”

来自分类Dev

无法读取JSON:字段名称输入意外结束

来自分类Dev

Rails无法读取以“ false”值作为属性的JSON请求

来自分类Dev

.ajax JSON TypeError:无法读取未定义的属性“ length”

来自分类Dev

无法读取未定义JSON的属性“ 0”

来自分类Dev

AngularJS-$ httpBackend无法读取嵌套的JSON属性

Related 相关文章

热门标签

归档