Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to update a JIRA issue using Visual Studio 2015, Microsoft Razor, and C# with Json.Net 10.0.2. The code is:

public String updateJiraIssue(object objJira2) {
    JiraService.open("PUT", JiraUrl + "/rest/api/2/issue/NPI-24");
    JiraService.setRequestHeader("Content-Type", "application/json");
    JiraService.setRequestHeader("Accept", "application/json");
    JiraService.setRequestHeader("X-Atlassian-Token", "nocheck");
    JiraService.setRequestHeader("Authorization", "Basic " + GetEncodedCredentials());
    var myJSON = Json.stringify(JiraJson);
    JiraService.send(myJSON);
    String response = JiraService.responseText;
    JiraService.abort();
    return response;
}

The error occurs in:

var myJSON = Json.stringify(JiraJson);

The JSON is:

string jsonString = @"{""fields"":{""customfield_12302"":{""name"":""xyz""}}}";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
255 views
Welcome To Ask or Share your Answers For Others

1 Answer

JSON.stringify() is a javascript function, which you would call from a web page script to serialize an object to JSON before making an ajax request.

In C#, there is a Json class in the System.Web.Helpers namespace, but its serialization method is called Encode, not stringify. Note this class uses the JavaScriptSerializer internally to do its work; it does not depend on Json.Net.

If you want to use Json.Net, you should be calling JsonConvert.SerializeObject() instead:

var myJSON = JsonConvert.SerializeObject(objJira2);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...