Json does not contain a definiton for 'stringify'?

感情迁移 提交于 2019-12-25 19:13:11

问题


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""}}}";

回答1:


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


来源:https://stackoverflow.com/questions/43193750/json-does-not-contain-a-definiton-for-stringify

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!