How can we prepare "valid JSON" from Linkedin Share API

huangapple go评论84阅读模式
英文:

How can we prepare "valid JSON" from Linkedin Share API

问题

最近,从我们的日志中,我们看到了这个信息:

httpRes status received 400 Bad Request for this linkedinToken AQUz3sCODu312rHNtNfuns3awy0xoUxxxxxxxxxxx.
With Request: {"content":{"submitted-url":"http://mpg.smh.re/2Ra","title":"Gestionnaire sinistre H/F − Belgique ","description":"Responsable de la gestion de dossiers sinistres dans leur intégralité, vous serez en contact avec de nombreux interlocuteurs (compagnies d’assurances, clients et bureaux locaux).","submitted-image-url":"http://www.morganphilipsexecutivesearch.com/wp-content/uploads/2014/09/fyte-smarpshare.jpg"},"visibility":{"code":"anyone"},"comment":"FYTE, cabinet de recrutement spécialisé recrute pour l’un de ses clients situé en Belgique un Gestionnaire sinistre H/F."}.
Response body: {
"errorCode": 0,
"message": "Couldn't parse Json body: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: java.io.StringReader@42ea5bc1; line: 1, column: 187]",
"requestId": "0GYQWP14U9",
"status": 400,
"timestamp": 1423490252325
}

LinkedIn API表示无法解析JSON数据。我们怀疑是字符"é"或"’"没有被JAVA JSON解析器处理。

我的问题是,是否还有其他特殊/Unicode字符需要我们注意?因为这个JSON数据是由Go的内置函数进行编组的。

更新:我最近发现"换行符"("CTRL-CHAR, code 10")是这个问题的关键。"换行符"字符出现在"...leur intégralité,"之后。我的问题现在是,为什么Go的内置JSON编组器没有处理它。

英文:

Recently, from our log, we saw this:

httpRes status received 400 Bad Request for this linkedinToken AQUz3sCODu312rHNtNfuns3awy0xoUxxxxxxxxxxx.
 With Request: {"content":{"submitted-url":"http://mpg.smh.re/2Ra","title":"Gestionnaire sinistre H/F − Belgique ","description":"Responsable de la gestion de dossiers sinistres dans leur intégralité,
 vous serez en contact avec de nombreux interlocuteurs (compagnies 
d’assurances, clients et bureaux locaux).","submitted-image-url":"http://www.morganphilipsexecutivesearch.com/wp-content/uploads/2014/09/fyte-smarpshare.jpg"},"visibility":{"code":"anyone"},"comment":"FYTE, cabinet de recrutement spécialisé recrute pour l’un de ses clients situé en Belgique un Gestionnaire sinistre H/F."}.
 Response body: {
  "errorCode": 0,
  "message": "Couldn't parse Json body: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: java.io.StringReader@42ea5bc1; line: 1, column: 187]",
  "requestId": "0GYQWP14U9",
  "status": 400,
  "timestamp": 1423490252325
}

LinkedIn API said that it couldn't parse JSON body. Our doubt is that either character "é" or "’" is not handled by JAVA JSON parser.

My question is that is there any other special/unicode characters that we should be aware of? Because this JSON body was marshaled by Go's built-in.

UPDATE: I recently discovered that "line feed" ("CTRL-CHAR, code 10") is the key to this issue. "Line feed" character appears after "...leur intégralité,". My question now is that why doesn't Go built-in JSON marshaller handle that


</details>


# 答案1
**得分**: 2

JSON可以处理Unicode字符...前提是它们被正确编码。

然而,错误信息显示:

    非法的未引用字符((CTRL-CHAR,代码10))

这似乎是在说你的JSON中有一个控制字符。JSON语法规定,未转义的控制字符不允许出现在字符串中。

现在,如果我们假设10是十进制,那么它是一个换行符。所以我会在JSON开始位置的大约187个字符处寻找一个原始换行符。

------------------

&gt; 我现在的问题是为什么Go内置的JSON编组器不能处理这个。

有两种可能性:

  - 这是一个bug,或者
  - 你没有正确使用它。

<details>
<summary>英文:</summary>

JSON can cope with Unicode characters ... provided that they are properly encoded.

However the error message says:

    Illegal unquoted character ((CTRL-CHAR, code 10))

which seems to be saying that you have a control character in the JSON.  The JSON syntax states that unescaped control characters are not permitted in strings.

Now if we assume that 10 is decimal, then it is a newline character.  So I would look for a raw newline within the JSON about 187 characters from the start.

------------------

&gt; My question now is that why doesn&#39;t Go built-in JSON marshaller handle that.

Two possibilities:

  - it is a bug, or
  - you are not using it correctly.



</details>



huangapple
  • 本文由 发表于 2015年2月9日 22:39:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/28412257.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定