Tuesday 9 May 2017

Json response breaking into non valid UTF

Im currently getting a JSON response from a Chinese website that is supposed to return Chinese characters with the following code

  getShopInfo(req, res, next) {
    const shopId = decodeURIComponent(req.params.shopNick);
    const tbReq = new TopClient({
      'appkey': config.regAppKey,
      'appsecret': config.regAppSecret,
      'REST_URL': config.tbApiUrl
    });

    tbReq.execute('taobao.shop.get', {
      nick: shopId,
      fields: 'sid, cid, nick, title, desc, bulletin, pic_path, created, modified, shop_score, item_score, service_score, delivery_score'
    }, (err, response) => {
      if (err) {
        res.status(500).json(err);
      }

      res.json(response);
    });
  }

However instead of converting properly it is returning REPLACEMENT CHARACTER (U+FFFD) here is a sample response

{
  "image": "//img.example.com/uploaded/i4/TB1PsJQPpXXXXcdapXXXXXXXXXX_!!0-item_pic.jpg_180x180.jpg",
  "id": "18637235806",
  "title": "\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd̲\ufffdƷ5\ufffdа\ufffd\ufffdʴ\ufffd\ufffd̾\ufffd\ufffd\ufffd\ufffd\ufffdGeneral",
  "price": "55.00 ",
  "sold": "188"
}

Is there any reason why this would be happening?



via NooBskie

No comments:

Post a Comment