print(order_result) 打印出来的结果为:{"lattice":[{"json_1best":"{\"st\":{\"sc\":\"0.00\",\"pa\":\"0\",\"rt\":[{\"ws\":[{\"cw\":[{\"w\":\"12345678901234567890123\",\"wp\":\"n\",\"wc\":\"0.0000\"}],\"wb\":1,\"we\":444},{\"cw\":[{\"w\":\". \",\"wp\":\"p\",\"wc\":\"0.0000\"}],\"wb\":444,\"we\":444},{\"cw\":[{\"w\":\"\",\"wp\":\"g\",\"wc\":\"0.0000\"}],\"wb\":444,\"we\":444}]}],\"bg\":\"370\",\"rl\":\"0\",\"ed\":\"4880\"}}"}],"lattice2":[{"lid":"0","end":"4880","begin":"370","json_1best":{"st":{"sc":"0.00","pa":"0","rt":[{"nb":"1","nc":"1.0","ws":[{"cw":[{"w":"12345678901234567890123","wp":"n","wc":"0.0000"}],"wb":1,"we":444},{"cw":[{"w":". ","wp":"p","wc":"0.0000"}],"wb":444,"we":444},{"cw":[{"w":"","wp":"g","wc":"0.0000"}],"wb":444,"we":444}]}],"pt":"reserved","bg":"370","si":"0","rl":"0","ed":"4880"}},"spk":"段落-0"}]} 那么如何打印出{\"ws\":[{\"cw\":[{\"w\":\"12345678901234567890123\",\"wp\":\"n\",\"wc\":\"0.0000\"}里面的内容
时间: 2023-07-17 09:12:15 浏览: 141
要打印出{\"ws\":[{\"cw\":[{\"w\":\"12345678901234567890123\",\"wp\":\"n\",\"wc\":\"0.0000\"}里面的内容,你可以按照以下步骤操作:
1. 首先,解析打印出的结果字符串为一个字典对象。你可以使用内置的json模块来完成这个任务。示例代码如下:
```python
import json
order_result = '{"lattice":[{"json_1best":"{\"st\":{\"sc\":\"0.00\",\"pa\":\"0\",\"rt\":[{\"ws\":[{\"cw\":[{\"w\":\"12345678901234567890123\",\"wp\":\"n\",\"wc\":\"0.0000\"}],\"wb\":1,\"we\":444},{\"cw\":[{\"w\":\". \",\"wp\":\"p\",\"wc\":\"0.0000\"}],\"wb\":444,\"we\":444},{\"cw\":[{\"w\":\"\",\"wp\":\"g\",\"wc\":\"0.0000\"}],\"wb\":444,\"we\":444}]}],\"bg\":\"370\",\"rl\":\"0\",\"ed\":\"4880\"}}"}],"lattice2":[{"lid":"0","end":"4880","begin":"370","json_1best":{"st":{"sc":"0.00","pa":"0","rt":[{"nb":"1","nc":"1.0","ws":[{"cw":[{"w":"12345678901234567890123","wp":"n","wc":"0.0000"}],"wb":1,"we":444},{"cw":[{"w":". ","wp":"p","wc":"0.0000"}],"wb":444,"we":444},{"cw":[{"w":"","wp":"g","wc":"0.0000"}],"wb":444,"we":444}]}],"pt":"reserved","bg":"370","si":"0","rl":"0","ed":"4880"}},"spk":"段落-0"}]}'
result_dict = json.loads(order_result)
```
2. 然后,通过字典的键值访问方式,获取到目标内容。示例代码如下:
```python
target_content = result_dict["lattice"][0]["json_1best"]["st"]["rt"][0]["ws"][0]["cw"][0]["w"]
```
3. 最后,打印出目标内容。示例代码如下:
```python
print(target_content)
```
这样,你就可以打印出{\"ws\":[{\"cw\":[{\"w\":\"12345678901234567890123\",\"wp\":\"n\",\"wc\":\"0.0000\"}里面的内容了。
阅读全文