本帖最后由 恒美恒美 于 2024-9-30 14:34 编辑
通过api返回的订单数据是JSON数据, 我用循环命令循环写入数据表, 有一个问题是,有可能一次返回一条数据, 有可能一次返回多条数据, 返回多条数据时是一个列表形式,就可以循环, 但是只返回一条数据时,是json数据, json数据不能循环, 所以就出错了, 我在服务端命令里加了判断去判断返回的是列表还是json ,但是感觉不太对, 有没有其他方法,或者是把json和列表转换成同一种格式循环写入- {"adjust_fee":"0.00",
- "buyer_nick":"h**",
- "buyer_open_uid":"AAEFCekzABHD55D7_dBjknvv",
- "buyer_rate":"false",
- "consign_time":"2024-09-28 15:34:42",
- "created":"2024-09-28 14:19:35",
- "discount_fee":"90.00","modified":"2024-09-28 15:34:46",
- "no_shipping":"false","num":"1","num_iid":"684046548848",
- "oaid":"114Mf5xFS1SSiaFDwwNic0V7icrFo37U7rKdA8xFgkzrQaynswYTSGU8knlhvOicpN1uY4Jpuy9",
- "pay_time":"2024-09-28 14:19:40",
- "payment":"890.00",
- "pic_path":"https://img.alicdn.com/bao/uploaded/i2/2456129801/O1CN01ZECmaA2MGunfvcfBj_!!2456129801.jpg",
- "post_fee":"0.00",
- "price":"1960.00",
- "received_payment":"0.00",
- "receiver_address":"大**街道**村靴子礁瑞金海产品**公司",
- "receiver_city":"大连市",
- "receiver_district":"金州区",
- "receiver_mobile":"***********",
- "receiver_name":"陈**",
- "receiver_state":"辽宁省",
- "receiver_town":"大李家街道",
- "receiver_zip":"000000",
- "seller_flag":"0",
- "seller_rate":"false",
- "service_type":{},
- "shipping_type":"express",
- "status":"WAIT_BUYER_CONFIRM_GOODS",
- "tid":"4060670365019834309",
- "total_fee":"1960.00","type":"fixed"}
复制代码 这是返回一条订单的,这种就不能循环,可以直接写入,
- [{"adjust_fee":"0.00",
- "buyer_nick":"h**",
- "buyer_open_uid":"AAEFCekzABHD55D7_dBjknvv",
- "buyer_rate":"false",
- "consign_time":"2024-09-28 15:34:42",
- "created":"2024-09-28 14:19:35",
- "discount_fee":"90.00",
- "modified":"2024-09-28 15:34:46",
- "no_shipping":"false",
- "num":"1",
- "num_iid":"684046548848",
- "oaid":"114Mf5xFS1SSiaFDwwNic0V7icrFo37U7rKdA8xFgkzrQaynswYTSGU8knlhvOicpN1uY4Jpuy9",
- "pay_time":"2024-09-28 14:19:40",
- "payment":"890.00",
- "pic_path":"https://img.alicdn.com/bao/uploaded/i2/2456129801/O1CN01ZECmaA2MGunfvcfBj_!!2456129801.jpg",
- "post_fee":"0.00",
- "price":"1960.00",
- "received_payment":"0.00",
- "receiver_address":"大**街道**村靴子礁瑞金海产品**公司","receiver_city":"大连市","receiver_district":"金州区",
- "receiver_mobile":"***********",
- "receiver_name":"陈**",
- "receiver_state":"辽宁省",
- "receiver_town":"大李家街道",
- "receiver_zip":"000000",
- "seller_flag":"0",
- "seller_rate":"false",
- "service_type":{},
- "shipping_type":"express",
- "status":"WAIT_BUYER_CONFIRM_GOODS",
- "tid":"4060670365019834309",
- "total_fee":"1960.00",
- "type":"fixed"},
- {"adjust_fee":"0.00",
- "buyer_nick":"x**",
- "buyer_open_uid":"AAHRCekzABHD55D7_dBrMZL9",
- "buyer_rate":"false",
- "consign_time":"2024-07-17 16:44:17",
- "created":"2024-07-16 23:02:05",
- "discount_fee":"180.00",
- "end_time":"2024-08-03 16:45:54",
- "modified":"2024-09-28 14:51:27",
- "no_shipping":"false",
- "num":"1",
- "num_iid":"559222886228",
- "oaid":"1IeIUmrodoDroX1icbtlgw51SbiaEkibn7ibVtMRs6rwUW837U6mLvOfVoce3pd2kOoMRzmxiaof",
- "pay_time":"2024-07-16 23:19:22",
- "payment":"1700.00",
- "pic_path":"https://img.alicdn.com/bao/uploaded/i4/2456129801/O1CN01z3fqW82MGuTnkTknc_!!2456129801.jpg",
- "post_fee":"0.00",
- "price":"3760.00",
- "received_payment":"1700.00",
- "receiver_address":"三*街道 **大厦****",
- "receiver_city":"西安市",
- "receiver_district":"未央区",
- "receiver_mobile":"***********",
- "receiver_name":"王**",
- "receiver_phone":{},
- "receiver_state":"陕西省",
- "receiver_town":"三桥街道",
- "receiver_zip":"710016",
- "seller_flag":"4",
- "seller_rate":"false",
- "service_type":{},
- "shipping_type":"express",
- "status":"TRADE_FINISHED",
- "tid":"3970788192097304109",
- "total_fee":"3760.00","type":"fixed"}]
复制代码 这是返回多条订单的, 加了一个中括号. 这种需要循环写入
现在不确定每次返回的数据是一条还是多条, 如何能将返回数据不管是多条还是单挑都循环写入, 或者直接写入,
|