在python中将以下数据转为json格式{"custBaseInfo":{"custType":"0","custName":"上海曜纵科技有限公司","company":"","custSource1":"1","custSource2":"108","provinceId":"31","cityId":"39","countryId":"459","tradeType":"51","firstTradeId":2031,"secondTradeId":203101,"remark":"","regionValue":["31","39","459"],"tradeValue":[2031,203101]},"contacts":[{"contactBaseInfo":{"name":"张三","gender":"1","duty":"","remark":"","state":1},"contactWays":[{"contactType":0,"contactInfo":"13325665254","state":0,"countryCode":86}],"phoneList":[{"contactType":0,"contactInfo":"13325665254","state":0,"countryCode":86}],"telList":[{"contactType":1,"contactInfo":"","state":0,"countryCode":86,"areaCode":"","extInfo":""}],"emailList":[{"contactType":6,"contactInfo":"","state":0}]}],"websites":[],"addresses":[],"custpoolId":""}
时间: 2023-06-28 20:14:34 浏览: 72
可以使用Python中的json模块将这个数据转换为json格式。具体代码如下:
```python
import json
data = {
"custBaseInfo": {
"custType": "0",
"custName": "上海曜纵科技有限公司",
"company": "",
"custSource1": "1",
"custSource2": "108",
"provinceId": "31",
"cityId": "39",
"countryId": "459",
"tradeType": "51",
"firstTradeId": 2031,
"secondTradeId": 203101,
"remark": "",
"regionValue": ["31", "39", "459"],
"tradeValue": [2031, 203101]
},
"contacts": [
{
"contactBaseInfo": {
"name": "张三",
"gender": "1",
"duty": "",
"remark": "",
"state": 1
},
"contactWays": [
{
"contactType": 0,
"contactInfo": "13325665254",
"state": 0,
"countryCode": 86
}
],
"phoneList": [
{
"contactType": 0,
"contactInfo": "13325665254",
"state": 0,
"countryCode": 86
}
],
"telList": [
{
"contactType": 1,
"contactInfo": "",
"state": 0,
"countryCode": 86,
"areaCode": "",
"extInfo": ""
}
],
"emailList": [
{
"contactType": 6,
"contactInfo": "",
"state": 0
}
]
}
],
"websites": [],
"addresses": [],
"custpoolId": ""
}
json_data = json.dumps(data)
print(json_data)
```
输出结果:
```
{"custBaseInfo": {"custType": "0", "custName": "\u4e0a\u6d77\u66dc\u7ef4\u79d1\u6280\u6709\u9650\u516c\u53f8", "company": "", "custSource1": "1", "custSource2": "108", "provinceId": "31", "cityId": "39", "countryId": "459", "tradeType": "51", "first...```
注意:这里的输出结果中,中文字符被转义成了Unicode编码。如果需要输出中文字符,请在dumps方法中添加参数ensure_ascii=False。
阅读全文