首页 > 解决方案 > 如何将数据作为字典添加到 json 文件?

问题描述

我有一个 JSON 文件来使用它来调用 API。我想向它添加一些新数据

我尝试使用将对象添加到 JSONLibrary 的 JSON,但它没有按预期工作。这是 Json 文件。

{  
    "customer_name":"Nguyễn Lê Cường",
    "sender":{  
        "fullname":"Nguyễn Lê Cường",
        "phone":"0932028646",
        "address":"234 Trương Minh Ký, Phường 1, Tân Bình, Hồ Chí Minh, Việt Nam",
        "region_id":1455,
        "district":"Quận Tân Bình",
        "province":"Hồ Chí Minh",
        "location":[  
            10.795365,
            106.66720800000007
        ]
    },
    "group_id":23,
    "service_id":1,
    "fee_ship":0,
    "service_package_type":"SGN-TRANS-2500",
    "hub":"HCM",
    "payment_type":3,
    "note":"note for driver",
    "truck_payload":2500,
    "content":"Đơn hàng nguyên chuyến",
    "order_time":"2019-08-15T09:24:55.192Z",
    "stop_points":[  
        {  
            "fullname":"Nguyễn Lê Cường",
            "phone":"0932028646",
            "address":"234 Trương Minh Ký, Phường 1, Tân Bình, Hồ Chí Minh, Việt Nam",
            "region_id":1455,
            "district":"Quận Tân Bình",
            "province":"Hồ Chí Minh",
            "location":[  
                10.795365,
                106.66720800000007
            ],
            "sort":1,
            "pick_items":{  
                "number_of_items":0,
                "weight":0,
                "cubic_volume":[  
                    0,
                    0,
                    0
                ],
                "items":[  

                ]
            },
            "drop_items":{  
                "number_of_items":0,
                "weight":0,
                "cubic_volume":[  
                    0,
                    0,
                    0
                ],
                "items":[  

                ]
            },
            "pick_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "drop_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "note":"this is the note",
            "paper":"CTDK01 CTDK02",
            "cod":0,
            "address_detail":"Hẻm 35 Trương Minh Ký "
        },
        {  
            "fullname":"Nguyễn Lê Minh",
            "phone":"0932228888",
            "address":"146 Pasteur, Bến Nghé, Quận 1, Hồ Chí Minh, Việt Nam",
            "region_id":1442,
            "district":"Quận 1",
            "province":"Hồ Chí Minh",
            "location":[  
                10.775334,
                106.70081000000005
            ],
            "sort":2,
            "pick_items":{  
                "number_of_items":0,
                "weight":0,
                "cubic_volume":[  
                    0,
                    0,
                    0
                ],
                "items":[  

                ]
            },
            "drop_items":{  
                "number_of_items":0,
                "weight":0,
                "cubic_volume":[  
                    0,
                    0,
                    0
                ],
                "items":[  

                ]
            },
            "pick_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "drop_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "note":"this is note 2",
            "paper":"CTDK03",
            "cod":0,
            "address_detail":"146/55 Pasteur"
        }
    ] }

这是我要添加到 {
"fullname":"Nguyễn Lê Minh", "phone":"0932228888", "address":"146 Pasteur, Bến Nghé, Quận 1, Hồ Chí Minh, Việt Nam" , "region_id":1442, "district":"Quận 1", "province":"Hồ Chi Minh", "location":[
10.775334, 106.70081000000005 ], "sort":2, "pick_items":{
"number_of_items" :0,“重量”:0,“立方体积”:[
0, 0, 0 ],“项目”:[

                ]
            },
            "drop_items":{  
                "number_of_items":0,
                "weight":0,
                "cubic_volume":[  
                    0,
                    0,
                    0
                ],
                "items":[  

                ]
            },
            "pick_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "drop_papers":[  
                {  
                    "code":"",
                    "name":"",
                    "description":"",
                    "type":""
                }
            ],
            "note":"this is note 2",
            "paper":"CTDK03",
            "cod":0,
            "address_detail":"146/55 Pasteur"
        }

它是“stop_points”的一部分,我尝试将对象添加到 JSON,但它返回的不是 stop_points 的一部分

标签: robotframework

解决方案


推荐阅读