json newline in process '\ r', '\ n' is

A, josn easy instructions

   json is a lightweight data-interchange format, a series format string. In the data exchange, it is often used to, legible, lightweight. Many places will use to wide use. Follows :( section taken json body)

"matchrule": {
        "tag_id": "2", 
        "sex": "1", 
        "country": "中国", 
        "province": "广东", 
        "city": "广州", 
        "client_platform_type": "2", 
        "language": "zh_CN"
    }

  I would like to know more about json format, access to relevant documents.

Two, josn passed '\ r', '\ n' problem

  In the transfer '\ r', when the character string json '\ n' is encountered josn format error. as follows:

  Gripping transmission network json body, being given by formatting check. I think content "RelNotes" is incomplete. The other half did not find quotes [ "] lead to resolution failure. Actually met because a line break at the arrows leading to parse json failure.

Therefore, I want to pass a line break in "RelNotes" but does not lead to a failure to resolve the receiving end. How this deal? ? ?

Three, josn treated with '\ r', '\ n' newline

  Obviously '\ r', '\ n' is a special meaning characters need to be escaped, the need to add an escape character before the character '\'. In practice, I was such a deal. Problem quickly resolved.

Here is my approach :( There are hidden bug )

  Find "\ r \ n", replace "\\ r \\ n", here is a test function. But hides a bug.

Fourth, modify hidden bug

  In our normal test is ok, there are colleagues travel to the field and found that this feature is still a problem. Ethereal see there also exists a line break. ? ? ? I think how this happened, obviously treated, the "\ r \ n", replace "\\ r \\ n" on it. ? ? ? Quickly Baidu search under, ha ha. . . Finally know. The original line breaks in question.

  Description is given below:

  The final modifications:

    Found "\ r", replace "\\ r", "\ n", replace "\\ n". Test solve the problem! ! !

    Because there is likely to use a computer MAC, line breaks is "\ r", leading to json parsing failed.

V. Summary of issues

  Just begun to address the changing line, not so much to consider. That is, "\ r \ n", replace "\\ r \\ n" on it, then the test is not the problem. In particular bug, when special circumstances arise, later found to untangle, oh, the problem turned out to be so ah! Also considered deepened knowledge points.

Read the original

Guess you like

Origin www.cnblogs.com/chuanfengzhang/p/12189176.html