span8
斯潘4
本教程将概述如何使用JSON数据和消息。将介绍JSON的转换和转换,以及GIS的转换和转换,以及如何解析和更新JSON。The exercises in this tutorial will require FME Desktop version 2017.0 or higher in order to leverage recent improvements in JSON support.
JSON是一种常见的数据交换格式,已成为支持网站和移动设备应用程序的主要选择之一。与XML相比,JSON is more lightweight than XML and does not have a separate schema document (XSD) making it an ideal messaging and exchange format.复杂模式是使XML难以使用的一个方面。JSON比XML更容易读取,which makes it user-friendly.例如,it does not have namespaces the way XML does.由于JSON不引用外部模式,因此更容易无限制地更新和存储数据。另一方面,没有自动验证JSON的方法,which is one of the reasons why XML /GML is chosen for standards-based exchange formats.
JSON is the data format of NoSQL databases,除了关系数据库(如Oracle)之外的另一个数据库选项,MySQL,PostgreSQL,MS SQL Server and others.
JSON is an encoding mechanism for describing structured data,例如用于消息传递和Web服务。用JSON,它可以创造一个功能性很强的,快速的Web应用程序,for example web messaging on social media sites.许多网站都提供网络订阅源,一些与坐标信息,some without.这些提要易于在服务器端导入和使用。
JSON-javascript对象表示法
XML-可扩展标记语言
数组-项目系列[0,1,2,3,4]
对象-数据结构中相关值的单位“name”:“bob”
jquery-从JSON数据结构中提取特性的路径
Relational databases have a schema and store attributes that are divided into flat database tables.另一方面,JSON是高度嵌套的,这意味着与关系数据模型相比,值被构造为嵌套对象,instead of tables.json值可以是一个数组,an object or a primitive (strings or numbers).
JSON向/从GIS转换数据的一个大挑战是数据建模的根本区别。地理信息系统通常具有关系结构,而JSON通常是面向对象的。实际上,这意味着JSON通常具有高度嵌套的树结构,and contains series / list features and multiple geometries.因此,在关系系统中,可能需要几个表和行来建模给定的JSON对象。
FME可以对复杂的数据对象建模,that in JSON are called by different names.While FME can convert any JSON object into an FME feature,the specific file structure of JSON has to be taken into consideration.本教程中的第一个示例将使用JSON阅读器读取带有数据检查器(DI)的文件。
JSON文本要么是具有语法“A”:5的对象,or an array with syntax [1,2,3].
FME | Database | JSON |
特征 | 记录 | Object |
属性 | 场 | Property |
表 | 逗号分隔 | 数组 |
JSON是一种嵌套格式,that contains more properties the deeper we go into a file.例如,in the code below the name : "SFO" of the type : "Airport" is nested one level below name : "JSONFeature" with type : "FeatureCollection".The features are listed in an array with geometry and properties as types.
“name”:“JSonfeature”,“type”:“FeatureCollection”,“features”:[“id”:“1001”,“geometry”:“type”:“点”,“坐标”:[-122.4194155,37.7749295],“properties”:“name”:“sfo”,“type”:“机场”]
JSON对象示例
这个JSON对象有一个结构或模式,当从Features数组中查询时,也可以在表中表示:
身份证件 | 几何类型 | 几何.坐标 | 属性名称 | 性质类型 |
一千零一 | 点 | [ -122.4194155,37.7749295 | SFO | 机场 |
表中表示的JSON对象示例
In order to read JSON we need to tell FME which nested objects should become features.JSON读取的FME方法提供了在JSON阅读器: Auto and JSON Query.自动模式工作更简单,相对平坦的JSON结构。You can always try the Auto mode first to see if FME can extract features from your JSON automatically.
JSON Query offers a more powerful mode that allows you to specify a filter query which extracts feature data from more complex nested structures.问题是JSON查询语法的构造可能有点困难。To help build these JSON query extraction expressions we added the tree selection tool.这可以在“特性对象的JSON查询”参数的JSON阅读器设置中访问。用户可以选择树的一部分,by clicking in the nested data structure.在上述情况下,we could simply select "properties" node in the tree to get the SFO Airport data and ignore the parent data above.
Example of the JSON Reader Tree View
一旦我们知道哪些对象应该成为特征,我们就可以选择将这些对象中的任何嵌套属性展平为特征属性和几何图形,以获得更典型的GIS关系结构。Flattening typically involves taking nested parent-child JSON objects and creating a parent.child field names on the FME features.Parent/child ids can also be recorded to support associations between features.Arrays become lists unless part of a geometry.
There are other ways,to process JSON within a workspace.例如,theJSON-FLATENERtransformer can flatten JSON objects,将对象键和值提取到一个功能的FME功能属性(JSON类别)中。Fragmenting is used for extracting portions of JSON formatted text into multiple new FME features using theJSONFragmenter.These transformers are often used to support messaging applications which are more dynamic in nature than a file translation workspace.
换一种方式,将FME特性写入JSON文档,我们使用JSontemplater转换器将FME属性合并到所需的JSON结构中。Each feature type typically is written into its own sub-template.一旦生成完整的JSON文档,the文本文件编写器is then used to write it to a file.注意,我们通常不使用FME JSON编写器,除非我们想要生成一个非常简单的没有嵌套的平面JSON结构。
简而言之,FME covers the full scope of JSON data transformations,both from JSON to GIS,and from GIS back to JSON.这个概述涵盖了JSON的背景及其挑战。JSON的FME方法包括术语和机场对象示例。下面的文章包含一个示例,说明如何使用JSON向希望在美国机场更新天气和状态的用户发送消息。
Converting from JSON to a spatial format (GIS)
JSON Writing with JSONTemplater
JSON Transformations: Extraction with JSONExtractor,JSONFlattener and JSONFragmenter
?2019安全亚搏在线软件公司|Legal