首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >阅读Json with features字段

阅读Json with features字段
EN

Stack Overflow用户
提问于 2020-06-19 18:18:13
回答 2查看 38关注 0票数 0

我有以下问题。我正在尝试读取一个Json文件,但是我没有得到想要的结果。我有以下数据。

我想要阅读功能,但在找出某个地方时有一个错误。

我在读取时收到错误信息:警告:非法字符串偏移量‘功能’

输出

代码语言:javascript
运行
复制
Array
(
    [objectIdFieldName] => OBJECTID
    [uniqueIdField] => Array
        (
            [name] => OBJECTID
            [isSystemMaintained] => 1
        )

    [globalIdFieldName] => 
    [geometryProperties] => Array
        (
            [shapeAreaFieldName] => Shape__Area
            [shapeLengthFieldName] => Shape__Length
            [units] => esriMeters
        )

    [geometryType] => esriGeometryPolygon
    [spatialReference] => Array
        (
            [wkid] => 4326
            [latestWkid] => 4326
        )

    [fields] => Array
        (
            [0] => Array
                (
                    [name] => GEN
                    [type] => esriFieldTypeString
                    [alias] => GEN
                    [sqlType] => sqlTypeOther
                    [length] => 33
                    [domain] => 
                    [defaultValue] => 
                )

            [1] => Array
                (
                    [name] => cases
                    [type] => esriFieldTypeInteger
                    [alias] => Anzahl Fälle
                    [sqlType] => sqlTypeOther
                    [domain] => 
                    [defaultValue] => 
                )

            [2] => Array
                (
                    [name] => deaths
                    [type] => esriFieldTypeInteger
                    [alias] => Anzahl Todesfälle
                    [sqlType] => sqlTypeOther
                    [domain] => 
                    [defaultValue] => 
                )

        )

    [features] => Array
        (
            [0] => Array
                (
                    [attributes] => Array
                        (
                            [GEN] => Celle
                            [cases] => 220
                            [deaths] => 15
                        )

                    ...........

我的代码

代码语言:javascript
运行
复制
$url = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=GEN%20%3D%20%27CELLE%27&outFields=GEN,cases,deaths&outSR=4326&f=json";
$json = file_get_contents($url);
$data = json_decode($json,true); //decode json result as array and thenloop it
print '<pre>';
print_r($data);
foreach($data as $row){
echo $row['features']->$row['attributes']->$row['GEN'];
}

我在阅读中哪里错了?它只需要读一下括号里的内容,对吗?

所以实际上是features> attributes-> Gen来获取GEN查询

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-19 18:57:06

对不起,这是我的错,似乎没有读清楚你的问题。

使用GEN属性,您不需要使用循环来获取此值。

如果你想得到GEN,你的代码就应该是GEN。

代码语言:javascript
运行
复制
$url = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=GEN%20%3D%20%27CELLE%27&outFields=GEN,cases,deaths&outSR=4326&f=json";
$json = file_get_contents($url);
$data = (array) json_decode($json, true); //decode json result as array and thenloop it
print '<pre>';
print_r($data);
echo $data['features']['attributes']['GEN'];

// foreach($data as $row){
// echo $row['features']->$row['attributes']->$row['GEN'];
// }
票数 0
EN

Stack Overflow用户

发布于 2020-06-19 18:31:54

让我们尝试更改一下。

代码语言:javascript
运行
复制
foreach($data as $row){
   echo $row['features'][0]['attributes']['GEN'];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62468093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档