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");
}
}
}
錯誤
我在下面的線誤差,用於通知構造函數不能把0參數。好的,這很清楚。但是這個代碼我從Mozilla Persona得到。
var reader = new JsonReader();
UPDATE
我下面
代碼var reader = new JsonFx.Json.JsonReader();
有人能幫助我同樣的錯誤?
我在stackoverflow中發現了一些問題,如this one,你可以看到相同的一段代碼。
閱讀[MSDN Docs on JSONReader](http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.client.jsonreader.jsonreader.aspx)。構造函數需要兩個參數。 – xbonez
是的,但他是我的第一個將此與C#集成的應用程序,因此我遵循Mozilla網站中的示例,但在此行中似乎有誤。 –
該示例使用JsonFX JsonReader,它具有默認構造函數。什麼是你得到的錯誤。這是實際的AuthController源代碼:https://github.com/sergiotapia/ASP.Net-MVC3-Persona-Demo/blob/master/MVC3PersonaDemo/Controllers/AuthController.cs – Pete