該

這是 PlaidLinkResults 模型
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace SS.PFS.WebApp.Models
{
public class PlaidLinkResults
{
[JsonProperty("institution") ]
public Acklann.Plaid.Entity.Institution Institution { get; set; }
public Acklann.Plaid.Entity.Account Account { get; set; }
public string AccountId { get; set; }
public List<Acklann.Plaid.Entity.Account> Accounts { get; set; }
[JsonProperty("link_session_id")]
public string LinkSessionId { get; set; }
[JsonProperty("public_token")]
public string PublicToken { get; set; }
}
}
這是機構模型的代碼
using Acklann.Plaid.Institution;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace Acklann.Plaid.Entity
{
/// <summary>
/// Represents a banking institution.
/// </summary>
public class Institution
{
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>The identifier.</value>
[JsonProperty("institution_id")]
public string Id { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance has Multi-Factor Authentication.
/// </summary>
/// <value><c>true</c> if this instance has Multi-Factor Authentication; otherwise, <c>false</c>.</value>
[JsonProperty("has_mfa")]
public bool HasMfa { get; set; }
/// <summary>
/// Gets or sets the Multi-Factor Authentication selections.
/// </summary>
/// <value>The mfa selections.</value>
[JsonProperty("mfa")]
public string[] MfaSelections { get; set; }
[JsonProperty("mfa_code_type")]
public string MfaType { get; set; }
/// <summary>
/// Gets or sets the hexadecimal representation of the primary color used by the institution.
/// </summary>
[JsonProperty("primary_color")]
public string PrimaryColor { get; set; }
/// <summary>
/// Gets or sets the Base64 encoded representation of the institution's logo.
/// </summary>
[JsonProperty("logo")]
public string Logo { get; set; }
/// <summary>
/// Gets or sets the URL for the institution's website.
/// </summary>
/// <value>
/// The URL.
/// </value>
[JsonProperty("url")]
public string Url { get; set; }
/// <summary>
/// Gets or sets the credentials.
/// </summary>
/// <value>The credentials.</value>
[JsonProperty("credentials")]
public Credential[] Credentials { get; set; }
/// <summary>
/// Gets or sets the products.
/// </summary>
/// <value>The products.</value>
[JsonProperty("products")]
public string[] Products { get; set; }
/// <summary>
/// Gets or sets the country codes using the ISO-3166-1 alpha-2 country code standard.
/// </summary>
/// <value>
/// The countries.
/// </value>
[JsonProperty("country_codes")]
public string[] Countries { get; set; }
/// <summary>
/// Gets or sets the information about the institution's current status.
/// </summary>
[JsonProperty("status")]
public StatusSchema Status { get; set; }
/// <summary>
/// Represents an <see cref="Institution"/> login credentials.
/// </summary>
public struct Credential
{
/// <summary>
/// Gets or sets the label.
/// </summary>
/// <value>The label.</value>
[JsonProperty("label")]
public string Label { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the type of the data.
/// </summary>
/// <value>The type of the data.</value>
[JsonProperty("type")]
public string DataType { get; set; }
}
public class StatusSchema
{
/// <summary>
/// Gets or sets status information regarding Item adds via Link.
/// </summary>
[JsonProperty("item_logins")]
public InstitutionStatus ItemLogin { get; set; }
/// <summary>
/// Gets or sets the status information regarding transactions updates.
/// </summary>
[JsonProperty("transactions_updates")]
public InstitutionStatus Transactions { get; set; }
/// <summary>
/// Gets or sets the status information regarding Auth requests..
/// </summary>
/// <value>
/// The authentication.
/// </value>
[JsonProperty("auth")]
public InstitutionStatus Auth { get; set; }
/// <summary>
/// Gets or sets the status information regarding Balance requests.
/// </summary>
/// <value>
/// The balance.
/// </value>
[JsonProperty("balacne")]
public InstitutionStatus Balance { get; set; }
/// <summary>
/// Gets or sets the status information regarding Identity requests.
/// </summary>
[JsonProperty("identity")]
public InstitutionStatus Identity { get; set; }
}
}
}
uj5u.com熱心網友回復:
大多數情況下,發生這種情況是因為發送的資料格式錯誤。
注意到您如何格式化要發送的資料的一些問題,這導致您的 JSON 格式不正確。
請注意該results欄位如何沒有引號

因為你試圖自己構建字串
//...
data: '{ results: ' valueToPost '}',
//...
然后,模型系結器的任務是嘗試從格式錯誤的有效負載中推斷出所需的資料并將它們映射到模型。
我首先建議只將元資料按testPost原樣傳遞
//...
onSuccess: (public_token, metadata) => {
//...
testPost(metadata);
return true;
},
//...
并讓該函式處理格式。
function testPost(valueToPost) {
var data = { results : valueToPost }; //creating payload object
$.ajax({
type: "POST",
url: "/BankAccount/Link",
data: JSON.stringify(data), //formatting to JSON here
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Hello: " response.Name " .\nCurrent Date and Time: " response.DateTime);
},
failure: function (response) {
alert('failure: ' response.responseText);
},
error: function (response) {
//alert('error: ' response.responseText);
//document.getElementById('plaidMetadata2').value = response.responseText;
document.getElementById('plaidMetadata2').value = valueToPost;
}
});
}
該操作還應明確告訴模型系結器在哪里查找資料
[HttpPost]
public ActionResult Link([FromBody]Models.PlaidLinkResults results) {
var resultsetToSaveAsLinkedAccounts = results;
return View("Index");
}
這樣它就不必從可能的來源之一推斷資料
uj5u.com熱心網友回復:
好吧,也許我瘋了,但閱讀格子 HTML 評論:
// Plaid 插件的 onSuccess() 函式將向您的代碼回傳一個公共令牌和元資料物件。請使用我們的 API向我們發送公共令牌,我們將從 Plaid 查詢銀行賬戶的路由號碼和帳號,并將其安全地存盤在我們的系統中。
現在,當我查看您的 onSuccess 代碼時:
document.getElementById('plaidToken').innerHTML = public_token;
document.getElementById('plaidMetadata2').value = JSON.stringify(metadata, null, 2);
//testPost(JSON.stringify(metadata, null, 2));
// testPost(metadata);
testPost(JSON.stringify(metadata));
您同時獲得令牌和元資料,但在我看來,您一直在嘗試向他們發送元資料。他們只要求公共令牌。為什么要發送元資料?我錯過了什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/349254.html
標籤:查询 阿贾克斯 asp.net-mvc 邮政 格子
