Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

c# - Json does not contain a definiton for 'stringify'?

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

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

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...