ARC:
我将返回的json保存在.json文件中,并使用以下命令将其转换为pandas数据框:
temp_json = pd.read_json('TempJson.json', orient='columns')
这很有效。 但后来我在Python 2.7.13中使用了requests模块,特别是:
myResponse = requests.post(url, json= payload, headers = headers)
jData = json.loads(myResponse.content)
1)json结构与temp_json有很大不同,2)它完全破坏了我的代码。知道为什么吗?
来自temp_json的片段:
{
"expand": "schema,names",
"startAt": 0,
"maxResults": 250,
"total": 3,
"issues": [
{
"expand": "operations,editmeta,changelog,transitions,renderedFields",
"id": "1954523",
"key": "SPGC-14075",
"fields": {"summary": "QA: Build concentration support into CDC automation",
"issuetype": {
"self": "https://itec-jira.fmr.com/rest/api/2/issuetype/20",
"id": "20",
"description": "Default sub-task",
"iconUrl": "https://itec-
jira.fmr.com/images/icons/issuetypes/subtask_alternate.png",
"name": "Sub task",
"subtask": true
来自python json的示例:
{
"issues": [
{
"key": "SPGC-25646",
"fields": {
"status": {
"statusCategory": {
"name": "To Do",
"self": "https://itec-jira.fmr.com/rest/api/2/statuscategory/2",
"id": 2,
"key": "new",
"colorName": "blue-gray"
},.....
答案 0 :(得分:0)
json.loads
将创建一个python dict,它被散列,因此内容将以乱序排列。检查json.loads是否为请求和tempfile返回相同的dict。如果它们不同则数据不同。您可以使用漂亮的打印库来帮助您调试深层嵌套的json。