私は、次の形式で値を返すされているWeb ASPのAPIがあります。エラーが発生する理由現在のJSONオブジェクトを逆シリアル化できませんか?
{"idDoc":18,"idDocRipristino":0,"relCau":1,"numDoc":"2","data":"2016-10-17T00:00:00","relTavolo":3,"apertura":"4","orario":"2016-10-17T00:00:00","idAna":0,"nominativo":"5","relOpe":6,"totale":7.0,"note":"8","idAsp":0,"romana":0,"relOpe_Port":0}
をそして、私はDevExpress社のGridViewのにデータをバインドするためにWinフォームアプリケーションから以下のコードを使用していますが、私はエラーの下に取得しています:ここでは
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'WinFormVB.Documenti[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
は私のWinフォームのコードは、APIにアクセスし、JSONを使用してデータを読み込むことです:
Async Sub GetDocumenti(idDoc As Integer)
Dim Uri As String = "http://localhost:53917/api/Documenti/GetByIdDoc"
Using client = New HttpClient()
Using response = Await client.GetAsync([String].Format("{0}/{1}", Uri, idDoc))
If response.IsSuccessStatusCode Then
Dim DocumentisonData = Await response.Content.ReadAsStringAsync()
GridCtrlDocumenti.DataSource = JsonConvert.DeserializeObject(Of Documenti())(DocumentisonData).ToList()
Else
Dim result = DevExpress.XtraEditors.XtraMessageBox.Show("Sorry no data found!!", "Confirmation Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Using
End Using
End Sub
これは私のリポジトリである:
public DocumentiModel GetByIdDoc(int id)
{
using (var dbCtx = new USDevEntities())
{
var documenti = dbCtx.Documentis.Where(x => x.IDDoc == id).FirstOrDefault();
if (documenti != null)
{
return ConvertTo(documenti);
}
else
{
return null;
}
}
}
このエラーを解決する方法を教えてください。ありがとう。
JSONがちょうど単一のオブジェクトで、まだあなたは配列としてそれをシリアル化してみてください。 – Styxxy
私はJSONの新機能です。私の問題を解決する方法や答えを説明する例を教えてください。 – barsan
'Documenti'クラスを表示してください – Jim