['{"distance":1548,"oldx":2.0090292129863854,"oldy":1544.1428397435209,"x":"150.020","y":"165.441","angle":0.07454545454544359,"newY":1544.1428397435209,"dip":{"0":{"zangle":353.0731201171875,"xangle":357.38525390625,"yangle":356.912841796875},"1":{"zangle":353.067626953125,"xangle":357.3907470703125,"yangle":356.8963623046875},"2":{"zangle":353.0621337890625,"xangle":357.4017333984375,"yangle":356.8853759765625},"3":{"zangle":353.067626953125,"xangle":357.4127197265625,"yangle":356.8743896484375}},"newdistance":1544.1441466811198,"newX":2.0090292129863854}']python里面如何获取"newX":后的值
时间: 2023-07-02 22:17:32 浏览: 113
sentence.js:Sentence.js
可以使用 Python 的 json 库来解析该json字符串,并通过字典的方式获取所需的值。具体代码如下:
```python
import json
# 假设该字符串保存在变量data中
data = '{"distance":1548,"oldx":2.0090292129863854,"oldy":1544.1428397435209,"x":"150.020","y":"165.441","angle":0.07454545454544359,"newY":1544.1428397435209,"dip":{"0":{"zangle":353.0731201171875,"xangle":357.38525390625,"yangle":356.912841796875},"1":{"zangle":353.067626953125,"xangle":357.3907470703125,"yangle":356.8963623046875},"2":{"zangle":353.0621337890625,"xangle":357.4017333984375,"yangle":356.8853759765625},"3":{"zangle":353.067626953125,"xangle":357.4127197265625,"yangle":356.8743896484375}},"newdistance":1544.1441466811198,"newX":2.0090292129863854}'
# 解析json字符串
json_data = json.loads(data)
# 获取newX的值
new_x = json_data['newX']
# 打印newX的值
print(new_x)
```
运行该代码后,会输出`2.0090292129863854`,即"newX"后的值。
阅读全文