执行appapi接口时,数据在哪个地方转为json数据

bug问题 · zhensong1 · 于 6年前 发布 · 1630 次阅读

erp是python语言,在erp系统对接fecshop,fecshop成功处理了请求并返回了成功信息,但是erp那边处理时却提示解析不了json数据,原因就是fecshop返回的json是数组形式的,如图所示: 在request.text行下面,数据是array的json的。

共收到 2 条回复
Terry#16年前 0 个赞

转换成json,是Yii2的机制

接收json(request): https://github.com/fecshop/yii2_fecshop/blob/master/app/appapi/config/appapi.php

'request' => [
            'class' => 'yii\web\Request',
            'enableCookieValidation' => false,
            'parsers' => [
                 'application/json' => 'yii\web\JsonParser',
            ],
        ],

返回json(reponse): https://github.com/fecshop/yii2_fecshop/blob/master/app/appapi/modules/AppapiController.php

public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
        //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
        return $behaviors;
    }

对于你的问题: 原因就是fecshop返回的json是数组形式的, 看不懂你说的啥意思

http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-api-product-fetchone.html

返回的就是标准json格式,应该是你姿势不对。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics