【问题标题】:Replace piece of json替换一段json
【发布时间】:2021-09-12 13:43:45
【问题描述】:

我有一个包含地理数据的大 .json 文件。它是这个文件的一部分。它具有重复结构。 我想保存有关“id”和“area_value”的信息并删除或替换其他数据。

采用这种结构。

{'Number':['id'],'Area sq.m.': ['area_value'],'Forest cov':'None','Status':'None'}

解决这个问题的最佳方法是什么?

谢谢!

{
   "type":"FeatureCollection",
   "crs":{
      "type":"name",
      "properties":{
         "name":"EPSG:4326"
      }
   },
   "features":[
      {
         "type":"Feature",
         "properties":{
            "date_create":"15.03.2008",
            "statecd":"06",
            "cc_date_approval":null,
            "children":null,
            "adate":"23.08.2017",
            "cc_date_entering":"01.01.2014",
            "rifr_cnt":null,
            "parcel_build_attrs":null,
            "rifr":null,
            "sale_date":null,
            "area_unit":"055",
            "util_code":null,
            "util_by_doc":null,
            "area_value":115558.0,
            "application_date":null,
            "sale":null,
            "cad_unit":"383",
            "kvartal":"69:3:11",
            "parent_id":"69:3:11:248",
            "sale_cnt":null,
            "sale_doc_date":null,
            "date_cost":null,
            "category_type":"003008000000",
            "rifr_dep":null,
            "kvartal_cn":"69:03:0000011",
            "parent_cn":"69:03:0000011:248",
            "cn":"69:03:0000011:245",
            "is_big":false,
            "rifr_dep_info":null,
            "sale_dep":null,
            "sale_dep_uo":null,
            "parcel_build":false,
            "id":"69:3:11:245",
            "address":"\u0422\u0432\u0435\u0440\u0441\u043a\u0430\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c, \u0440-\u043d. \u0411\u0435\u043b\u044c\u0441\u043a\u0438\u0439, \u0441/\u043f. \u0415\u0433\u043e\u0440\u044c\u0435\u0432\u0441\u043a\u043e\u0435, \u0434. \u041e\u0441\u0438\u043f\u043e\u0432\u043e",
            "area_type":"009",
            "parcel_type":"parcel",
            "sale_doc_num":null,
            "sale_doc_type":null,
            "sale_price":null,
            "cad_cost":139698.06,
            "fp":null,
            "center":{
               "x":33.14727379331379,
               "y":55.87764081906541
            }
         }
      }

【问题讨论】:

  • SO 不是一个代码编写服务——你至少应该展示你到目前为止所做的工作。
  • 首先您需要安装 json 包,然后从下面的代码 sn-p 开始递归地深入研究数据结构
  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: json python-3.x


【解决方案1】:

您可以尝试以下方法:

import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 2021-10-09
    • 2015-10-31
    相关资源
    最近更新 更多