我的dict格式数据json_output
在Python中是这样的:
[{'code': 'Z0001001','dateList': [{'FDate': '2008-01-11T00:00:00','value': 308.7931034482759},{'FDate': '2008-01-18T00:00:00',{'FDate': '2008-01-25T00:00:00',{'FDate': '2008-01-31T00:00:00',{'FDate': '2008-02-08T00:00:00','value': 309.82758620689657},{'FDate': '2008-02-15T00:00:00',{'FDate': '2008-02-22T00:00:00',{'FDate': '2008-02-29T00:00:00',{'FDate': '2008-03-07T00:00:00','value': 323.9655172413793},{'FDate': '2008-03-14T00:00:00',{'FDate': '2008-03-21T00:00:00',{'FDate': '2008-03-31T00:00:00',{'FDate': '2008-04-11T00:00:00','value': 324.48275862068965},{'FDate': '2008-04-18T00:00:00',{'FDate': '2008-04-25T00:00:00',{'FDate': '2008-04-30T00:00:00',{'FDate': '2008-05-09T00:00:00','value': 326.2068965517241},{'FDate': '2008-05-16T00:00:00',{'FDate': '2008-05-23T00:00:00',{'FDate': '2008-05-30T00:00:00','value': 329.3333333333333}]},{'code': 'Z0001002','value': 294.2857142857143},'value': 297.14285714285717},'value': 307.14285714285717},'value': 309.2857142857143},'value': 309.2857142857143}]}]
然后我使用json.dumps()
将其转换为json格式,以便可以通过api将json数据转换为sql Server。
data_json = json.dumps(json_output)
from requests_negotiate_sspi import HttpNegotiateAuth
url = "http://xxx/api/xxx"
r_json = requests.post(url,data_json,headers={'Content-Type':'application/json'},auth=HttpNegotiateAuth())
print(r_json)
print(r_json.text)
print(r_json.status_code)
print(r_json.raise_for_status())
但是,当我运行它时,它给了我这样的错误:
{"errors":{"":["Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ZSFund.DataService.Web.Models.Code.CodeValueMaintainEntity' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection,IList) like List<T> that can be deserialized from a JSON array.
我试图将它们一次转换,就像一次将Z0001001
转换为sql一样,格式如下:
{'code': 'Z0001001','value': 329.3333333333333},}]}
它显示一切正常,没有任何错误,因此我想数组或列表可能有问题。有什么想法吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。