2017-02-14 18:38:51 2360次浏览 1条回答 0 悬赏 10 金钱

1,问题是这样的 我们公司这边是PHP端 需要POST数据到服务端去,服务端的语言是JAVA的,所以传过去的也是json数据。
2下面是我的json数据格式

{
    "action": "registerProduct",
    "app_key": "hufanjin@163.com",
    "data": {
        "productCode": "AU-QCQP50098",
        "chineseName": " 儿童汽车座椅增高垫深绿色1",
        "englishName": "sadfas",
        "categoryOne": "11",
        "registeredWeight": "1.29",
        "fixedVolumeWeight": "Y",
        "registeredLength": "40.00",
        "registeredWidth": "38.00",
        "registeredHeight": "18.00",
        "branded": "Y",
        "brandedName": "1",
        "model": "HG",
        "displayPageUrl": "www.baidu.com",
        "exportCountry": "CN",
        "inporCountry": "AU",
        "inportDeclaredvalue": "5.94",
        "exportDeclaredvalue": "5.94",
        "battery": "Y"
    },
    "format": "json",
    "language": "zh_CN",
    "platform": "SELLERERP",
    "sign": "608366A0D440BFB176BA3F13B6105873",
    "sign_method": "md5",
    "version": "1.0"
}

3.服务端返回是非法的json字符串。
4.自己的思路就是以为破坏了json的格式,可是验证并不存在json数据格式错误。
5.又或则是这个单引号或则双引号存在问题。

  • 回答于 2017-02-14 22:10 举报

    中文需要转义成Unicode模式吧

    3 条回复
    回复于 2017-02-15 08:53 回复

    接口那边要求中文不需要转义

    回复于 2017-02-15 11:20 回复

    发送的方式呢?是不是得定义utf-8 或者修改请求头为json格式

    回复于 2017-02-15 11:23 回复
    public static function http_post_json($url, $jsonStr)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json; charset=utf-8',
                'Content-Length: ' . strlen($jsonStr)
            )
        );
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
        return array($httpCode, $response);
    }
    

    这是我的请求方法

您需要登录后才可以回答。登录 | 立即注册
风
副董事长

深圳

注册时间:2015-03-28
最后登录:2023-10-07
在线时长:273小时23分
  • 粉丝30
  • 金钱17698
  • 威望70
  • 积分21128

热门问题