我只是嘗試反序列化一個Json數組,但它不起作用。 我可以在輸出框閱讀以下消息:在Newtonsoft中反序列化C#中的JSON數組
「Newtonsoft.Json.JsonReaderException:無效JavaScript屬性 標識符字符:」。路徑 '[0]',第2行,位置37」
我的代碼:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Newtonsoft;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace JsonTest
{
[Activity(Label = "JsonTest", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate
{
string json = @"[{
id': '1',
'nom': 'zooz',
'prenom': 'Jack'
}, {
'id': '2',
'nom': 'toto',
'prenom': 'Blaireau'
}]";
var a = JsonConvert.DeserializeObject<List<Person>>(json);
//JArray b = JArray.Parse(json);
Console.WriteLine(a);
// [email protected]};
};
}
public class Account
{
public string id { get; set; }
public string nom { get; set; }
public string prenom { get; set; }
}
public class Person
{
public Account person;
}
}
}
感謝你的幫助。
單引號(「)似乎是失蹤‘身份證’:」 1' – hellowstone
謝謝你。這是一個愚蠢的錯誤。 – Matthaousse