2013-02-06 3 views
1

Mozilla Persona 로그인으로 샘플 애플리케이션을 만들려고하는데 샘플 코드에서 오류가 발생했습니다.C#에서 JSON 읽기

CODE

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

ERROR

내가 생성자가 0 인수를 할 수 있음을 알리는 아래 줄에 오류를 얻었다. 좋습니다, 이것은 매우 분명합니다. 하지만이 코드는 Mozilla Persona에서 가져 왔습니다. UPDATE

var reader = new JsonReader(); 

나는

var reader = new JsonFx.Json.JsonReader(); 

누군가가 나를 도울 수

아래의 코드와 같은 오류가있어?

같은 코드를 볼 수있는 this one과 같은 몇 가지 질문을 stackoverflow에서 발견했습니다.

+3

[JSONReader의 MSDN 문서] (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.jsonreader.jsonreader.aspx)를 읽으십시오. 생성자는 두 개의 인수를 취합니다. – xbonez

+0

예,하지만 C#과 통합 된 첫 번째 응용 프로그램이므로 Mozilla 웹 사이트의 샘플을 따르지 만이 줄에는 잘못된 것처럼 보입니다. –

+0

샘플은 JsonFX JsonReader를 사용하며 기본 생성자를 사용합니다. 정확히 무엇이 오류입니까? 다음은 실제 AuthController 소스입니다. https://github.com/sergiotapia/ASP.Net-MVC3-Persona-Demo/blob/master/MVC3PersonaDemo/Controllers/AuthController.cs – Pete

답변

2

여기에서 얻을 수있는 최신 버전의 JsonFX로 업그레이드해야합니다 : https://github.com/jsonfx/jsonfx.

이 최신 버전에서는 JsonReader에 실제로 코드가 작동하도록하는 기본 생성자가 포함되어 있습니다.

버전 (아마도 이전 버전 here)에서 JsonReader에는 여러 개의 생성자가 있지만 0 개 인수는 허용되지 않습니다.