JIRA 休息 API 错误。无法识别的令牌创建问题

Posted

技术标签:

【中文标题】JIRA 休息 API 错误。无法识别的令牌创建问题【英文标题】:JIRA Rest API error. Unrecognized token creating a issue 【发布时间】:2015-03-05 03:46:36 【问题描述】:

通过 AJAX 和 REST API 添加问题并不走运。我可以让它与 Postmen 一起工作,不幸的是,无法通过 Ajax 请求获得它。

我创建的 JSON 很好,post 请求也很好。问题类型是我自己创建的,使用 Bug 给出了同样的问题。查看创建的 JSON 对象、我的错误和我的代码: JSON 对象(这是来自 console.log 的 sn-p):

错误

0: "无法识别的标记 'fils5poet5': 期待 'null', 'true', 'false' 或 NaN↵ 在 [来源: org.apache.catalina.connector.CoyoteInputStream@7b958ed2;线:1, 列:21]"

jira = 
   fields : 
      project : 
         key : "CIC"
      ,
      summary : "test",
      description: "test",
      issuetype : 
         name : "Sandbox item"
      
   
;

console.log(jira); //Also see image at top of this post.

// Submit to Jira api
$.ajax(
   type : "POST",
   dataType : "JSON",
   url : configuration.api_url,
   beforeSend:  function (xhr) 
      xhr.setRequestHeader ("Authorization", "Basic ItsAWrap!(itworks...)"),
      xhr.setRequestHeader ("Content-Type", "application/json");
   ,
   data : jira,
   success : (function(response) 
//Do something
)

【问题讨论】:

【参考方案1】:

您需要在发送之前JSON.stringify 您的 jira 变量。

【讨论】:

【参考方案2】:

你可以试试这样的:

jira = 
    "fields":
    
        "project":
        
            "key": "CIC"
        ,
        "summary": data["story.name"],
        "description": data["story.notes"],
        "issuetype":  "name": "Sandbox item" 
    
;

//THIS BADASS FUNCTION!!!
jira = JSON.stringify(jira);

$.ajax(
    type : "POST",
    url : configuration.api_url,
    dataType : "JSON",
    async : false,
    headers: 
        "Authorization": "Basic YeahSomethingInAWrap",
        "Content-Type": "application/json",
        "Accept": "application/json",
        "Cache-Control": "no-cache"
    ,
    data : jira,
    success : (function(response) 
        // Hide loader
        l.removeClass("show");

        // Alert Success Message
        alert("Melding succesvol ontvangen, bedankt!");

        // Close dialog
        $(".chrome-extension-dialog a.close").trigger("click");

    )
); 

【讨论】:

以上是关于JIRA 休息 API 错误。无法识别的令牌创建问题的主要内容,如果未能解决你的问题,请参考以下文章

com.fasterxml.jackson.core.JsonParseException:无法识别的令牌

如何修复:“无法识别的令牌'无法识别':期待('true','false'或'null')”使用Horton schema-registry

错误 ['\+' 是在创建 R 包时以“\+”开头的字符串中无法识别的转义

错误:无法识别的选择器发送到实例

pushwoosh 错误无法识别的选择器发送到实例 Cordova 1.7.0

错误:无法识别的命令:服务