2016-06-27 14 views
0

1つのAPIからデータを取得していて、別のAPIにPOSTしていますが、一部のレコードがエラーで終了しています。私はソースAPIの分野に不正な文字があることを知りました。JSONの無効な文字/エスケープ - 必要な文字

残念ながら私はURLEncode.encodeを使用することはできませんため、私の先のAPIの制限が存在するなどのエスケープや他のcontent-typeが、私の唯一のオプションは、手動のような所定の置換文字でこれらの文字を検索し、削除することです他の理由によるapplication/jsonもスペース/ハイフン。私のクライアントはこのアプローチにも同意しています。今私はこれらの文字のすべてを知りません。

私に応じて次の文字が問題を引き起こしている:

‘ 
” 
\ 
{ 
} 
[ 
] 

はP.S.

完全かつ正確


上記のリストでありますデータサンプル1

{ 
"name": "JSW-13867", 
"description": "Hi, 

    It would be extremely useful 
if it was possible to assign dates in the scrum board columns. 

#We already configure the sprint end date, 
so that could be displayed in the last column.\\\\ 
So, 
in our 
case, 
currently the last column is named "Done". 
What we 'd like to see is "Done (by 08/Jul/16)"\\\\ 
Although this information is 1 click away, 
so it wouldn 't be that big of an improvement (though easy to implement). But it makes sense if #2 below is implemented too.\\\\# 
What would be important in our 
case is the one - to - last column, 
which is "Test Done".\\\\ 
That would become "Test Done (by 01/Jul/16)".\\\\ 
What would be probably the correct/concise way, 
is a configuration on a board level, 
of an X amount of days before the sprint end date, 
for any column;which, 
ifset, 
will be displayed as per my examples(or similar). 

The last sentence of #2 is my recommendation/feature request... 

Thanks for a great product :) \\ 
\\ 
---- 
\\ 
original post: https://answers.atlassian.com/questions/39228431/answers/39228618","fields": {"field": [{"dataType": "ENUM_TYPE","id": "1716","name": "KFH-Issue-Issue Details:Issue Rating","hasChanged": true,"enumValue": {"name": "Very Low"}},{"dataType": "ENUM_TYPE","id": "530","name": "OPSS-Iss:Status","hasChanged": false,"enumValue": {"name": "Open"}},{"dataType": "ENUM_TYPE","id": "1717","name": "KFH-Issue-Issue Details:Issue Source","hasChanged": false,"enumValue": {"id": "4333","name": "IAD","index": 2,"hidden": false}}]}, "typeDefinitionId": "24", "primaryParentId": "26982"} 

p.s。データサンプル2

{ 
"name": "JSW-13840", 
"description": " h3. Summary If we set the *Incoming Authentication* on Fisheye side towards connection from JIRA and have the Executed As field specified by a user, the trigger creation will be mentioned that there is a problem with the configuration and mention that Fisheye status is Not Working  h3. Steps to Reproduce # Integrate JIRA with Fisheye. # Make sure that Fisheye is connected to a repo and at least One commit mentioning a JIRA ticket. # Edit OAuth Incoming Authentication on Fisheye side for connection with JIRA and set the Execute As field. # Update the configuration. # Navigate to JIRA and add a trigger to a specific workflow transition h3. Expected Result - The Diagnostics will state that the connection is Working  h3. Actual Result - The Diagnostics state that Fisheye connection is Not Working  h3. Notes - Using JIRA 7.1.7 and FerCru 4.0.4 - Tested this with 2LOi and it mention that there is no problem with the configuration. But, if we added a user on that particular field, it will back to Not Working after refreshing the page. - Samse as 2LOi, 2LO without any additional settings also did not have any issue. - Result of the diagnostic with Execute as {code}{ appLinkDiagnosticResults [{ name Julians-MacBook-Pro , type FishEye/Crucible , icon http //localhost 8717/jira_717/s/en_US-6hktwl/71011/b6b48b2829824b869586ac216d119363/5.0.7/_/download/resources/com.atlassian.applinks.applinks-plugin applinks-images/images/types/16fecru.png , supportedVersion true, accessible true, inboundStatus null, outboundStatus NOT_AUTHENTICATED , local2LOConfigured OK , remote2LOConfigured NOT_TESTED , working false}], dvcsDiagnosticResult { dvcsAccountDiagnosticResults []}, devToolsDocoUrl https //docs.atlassian.com/jira/jcore-docs-071/Integrating+JIRA+with+Code+Development+Tools {code} - Result of the diagnostic for aynthing without Execute as {code} { appLinkDiagnosticResults [{ name Julians-MacBook-Pro , type FishEye/Crucible , icon http //localhost 8717/jira_717/s/en_US-6hktwl/71011/b6b48b2829824b869586ac216d119363/5.0.7/_/download/resources/com.atlassian.applinks.applinks-plugin applinks-images/images/types/16fecru.png , supportedVersion true, accessible true, inboundStatus WORKING , outboundStatus WORKING , local2LOConfigured OK , remote2LOConfigured OK , working true}], dvcsDiagnosticResult { dvcsAccountDiagnosticResults []}, devToolsDocoUrl https //docs.atlassian.com/jira/jcore-docs-071/Integrating+JIRA+with+Code+Development+Tools } {code}", 
"fields": { 
    "field": [{ 
     "dataType": "ENUM_TYPE", 
     "id": "1716", 
     "name": "KFH-Issue-Issue Details:Issue Rating", 
     "hasChanged": true, 
     "enumValue": { 
      "name": "Low" 
     } 
    }, { 
     "dataType": "ENUM_TYPE", 
     "id": "530", 
     "name": "OPSS-Iss:Status", 
     "hasChanged": false, 
     "enumValue": { 
      "name": "Open" 
     } 
    }, { 
     "dataType": "ENUM_TYPE", 
     "id": "1717", 
     "name": "KFH-Issue-Issue Details:Issue Source", 
     "hasChanged": false, 
     "enumValue": { 
      "id": "4333", 
      "name": "IAD", 
      "index": 2, 
      "hidden": false 
     } 
    }] 
}, 
"typeDefinitionId": "24", 
"primaryParentId": "26982" 
} 
+1

文字列ですなぜあなたは他の皆のように適切にエスケープしませんか? json escape!= url-encode - > http://stackoverflow.com/questions/3020094/how-should-i-escape-strings-in-json – zapl

+0

私はそれを試しました、私の宛先APIは 'application/json'コンテンツのみをサポートしています。エンコード文字列が終わると、エンコードされた文字列のように見えます。エスケープは実用的ではありません。すべてのオブジェクトのすべてのキーを解析してエスケープする必要があります。実用的ではありません。 – Moon

+1

エスケープする方法はAPIが実際にその形式をサポートしているときに 'application/json'によって定義され、エスケープもサポートしています。編集:データをサンプルするコードビルディングですか、それとも他の場所からのものなのですか?それを変更できませんか? – zapl

答えて

0

Java JSONライブラリを使用して、宛先APIのデータを適切にjsonエンコードすることをお勧めします。あなたがデータの例を提供するなら、私たちはもっとあなたを助けるかもしれません。

UPDATE:ここ

public static void main(String[] args) { 
    String desc = "\"description\": \""; 
    String fields = "\",\"fields\""; 
    int indexStart = njson.indexOf(desc) + desc.length() ; 
    int indexEnd = njson.indexOf(fields); 

    String ex = njson.substring(indexStart, indexEnd); 

    String str = JSONObject.quote(ex); 

    String begin = njson.substring(0, indexStart - 1); 
    String end = njson.substring(indexEnd + 1); 

    String validJSon = begin + str + end; 

    JSONObject obj = new JSONObject(validJSon); 
} 

njsonあなたのデータで動作するコードはあなたの例から

+0

example posted above above – Moon

+0

@Moonはい、これは有効なJSONではありません。 "description"フィールドに二重引用符があります。ここから、 "description"から "fields" JSONはこの部分文字列をエンコードした後、有効なJSONオブジェクトを持ちます。 – madatx

+0

それは機能していました。また、特殊文字を置き換えたりエスケープしたりする方法もあります。 – Moon