C# 在C中读取JSON#

C# 在C中读取JSON#,c#,json,json.net,mozilla,C#,Json,Json.net,Mozilla,我正在尝试使用Mozilla Persona登录做一个示例应用程序,但示例代码中有一个错误 代码 public class AuthController : Controller { [HttpPost] public ActionResult Login(string assertion) { if (assertion == null) { // The 'assertion' key of the API wa

我正在尝试使用Mozilla Persona登录做一个示例应用程序,但示例代码中有一个错误

代码

public class AuthController : Controller
{
    [HttpPost]
    public ActionResult Login(string assertion)
    {
        if (assertion == null)
        {
            // The 'assertion' key of the API wasn't POSTED. Redirect,
            // or whatever you'd like, to try again.
            return RedirectToAction("Index", "Home");
        }

        using (var web = new WebClient())
        {
            // Build the data we're going to POST.
            var data = new NameValueCollection();
            data["assertion"] = assertion;
            data["audience"] = "https://example.com:443"; // Use your website's URL here.


            // POST the data to the Persona provider (in this case Mozilla)
            var response = web.UploadValues("https://verifier.login.persona.org/verify", "POST", data);
            var buffer = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, response);


            // Convert the response to JSON.
            var tempString = Encoding.UTF8.GetString(buffer, 0, response.Length);
            var reader = new JsonReader();
            dynamic output = reader.Read(tempString);

            if (output.status == "okay")
            {
                string email = output.email; // Since this is dynamic, convert it to string.
                FormsAuthentication.SetAuthCookie(email, true);
                return RedirectToAction("Index", "Home");
            }

            // Could not log in, do something else.
            return RedirectToAction("Index", "Home");
        }
    }
}
错误

我在下面的一行中得到一个错误,通知构造函数不能接受0个参数。好的,这很清楚。但这是我的密码

更新

public class AuthController : Controller
{
    [HttpPost]
    public ActionResult Login(string assertion)
    {
        if (assertion == null)
        {
            // The 'assertion' key of the API wasn't POSTED. Redirect,
            // or whatever you'd like, to try again.
            return RedirectToAction("Index", "Home");
        }

        using (var web = new WebClient())
        {
            // Build the data we're going to POST.
            var data = new NameValueCollection();
            data["assertion"] = assertion;
            data["audience"] = "https://example.com:443"; // Use your website's URL here.


            // POST the data to the Persona provider (in this case Mozilla)
            var response = web.UploadValues("https://verifier.login.persona.org/verify", "POST", data);
            var buffer = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, response);


            // Convert the response to JSON.
            var tempString = Encoding.UTF8.GetString(buffer, 0, response.Length);
            var reader = new JsonReader();
            dynamic output = reader.Read(tempString);

            if (output.status == "okay")
            {
                string email = output.email; // Since this is dynamic, convert it to string.
                FormsAuthentication.SetAuthCookie(email, true);
                return RedirectToAction("Index", "Home");
            }

            // Could not log in, do something else.
            return RedirectToAction("Index", "Home");
        }
    }
}
下面的代码也有同样的错误

var reader = new JsonFx.Json.JsonReader();
有人能帮我吗


我在stackoverflow中发现了一些问题,比如您可以看到相同的代码。

您需要升级到更新版本的JsonFX,您可以在这里获得:

在这个较新的版本中,
JsonReader
实际上包含了一个默认的构造函数,它应该使您的代码能够工作


在您可能拥有的版本中(我发现了较旧的版本),
JsonReader
有许多构造函数,但它们都不接受零参数。

。构造函数包含两个参数。是的,但这是我第一个将其与C#集成在一起的应用程序,因此我在Mozilla网站上使用了该示例,但这行中似乎有误。该示例使用JsonFX JsonReader,并且它确实有一个默认构造函数。你到底犯了什么错误。这是实际的AuthController源:错误是:“JsonFx.Json.JsonReader”不包含接受0个参数的构造函数