[英]Parsing JSON after conversion using XML2JSON
Calling an api and getting the response in xml.调用 api 并在 xml 中获取响应。 I am trying to convert the xml output to JSON using xml2json.
我正在尝试使用 xml2json 将 xml 输出转换为 JSON。 How can now i read directly the temperature parameter value from the json output.
现在我如何直接从 json 输出中读取温度参数值。
I am using following in my code,我在我的代码中使用以下,
var xml = response.body;
var result = convert.xml2json(xml, {compact: true, spaces: 4});
const jsonData = JSON.parse(result);
res.send(jsonData);
jsonData has all data but i just want to read eg temperature value jsonData 有所有数据,但我只想读取例如温度值
Here is the json output after conversion,这是转换后的json输出,
{
"_declaration": {
"_attributes": {
"version": "1.0",
"encoding": "UTF-8"
}
},
"wfs:FeatureCollection": {
"_attributes": {
"timeStamp": "2019-05-02T17:21:05Z",
"numberReturned": "864",
"numberMatched": "864",
"xmlns:wfs": "http://www.opengis.net/wfs/2.0",
"xmlns:gml": "http://www.opengis.net/gml/3.2",
"xmlns:BsWfs": "http://xml.fmi.fi/schema/wfs/2.0",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"xsi:schemaLocation": "http://www.opengis.net/wfs/2.0
http://schemas.opengis.net/wfs/2.0/wfs.xsd\n
http://xml.fmi.fi/schema/wfs/2.0
http://xml.fmi.fi/schema/wfs/2.0/fmi_wfs_simplefeature.xsd"
},
"wfs:member": [
{
"BsWfs:BsWfsElement": {
"_attributes": {
"gml:id": "BsWfsElement.1.1.1"
},
"BsWfs:Location": {
"gml:Point": {
"_attributes": {
"gml:id": "BsWfsElementP.1.1.1",
"srsDimension": "2",
"srsName": "http://www.opengis.net/def/crs/EPSG/0/4258"
},
"gml:pos": {
"_text": "60.20520 24.65220 "
}
}
},
"BsWfs:Time": {
"_text": "2019-05-02T18:00:00Z"
},
"BsWfs:ParameterName": {
"_text": "GeopHeight"
},
"BsWfs:ParameterValue": {
"_text": "36.57"
}
}
},
{
"BsWfs:BsWfsElement": {
"_attributes": {
"gml:id": "BsWfsElement.1.1.2"
},
"BsWfs:Location": {
"gml:Point": {
"_attributes": {
"gml:id": "BsWfsElementP.1.1.2",
"srsDimension": "2",
"srsName":
"http://www.opengis.net/def/crs/EPSG/0/4258"
},
"gml:pos": {
"_text": "60.20520 24.65220 "
}
}
},
"BsWfs:Time": {
"_text": "2019-05-02T18:00:00Z"
},
"BsWfs:ParameterName": {
"_text": "Temperature"
},
"BsWfs:ParameterValue": {
"_text": "2.97"
}
}
}
]
}
}
jsonData['wfs:FeatureCollection']['wfs:member'][0]['BsWfs:BsWfsElement']['BsWfs:ParameterName']['_text']
ex)前任)
jsonData = { "key0": 34 }
jsonArray = [ 35,36,37 ]
=> =>
console.log(jsonData['key0"]); // 34
console.log(jsonArray[0]); // 35
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.