我在C#新手我想反序列化在C#中JSON对象,但我得到的错误:C#JSON反序列化错误队列
We had a problem: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ZK4000_Example.JsonParser+user' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path 'usuarios', line 1, position 24.
Path '', line 1, position 1.
我读过从具有相同的其他用户的另一个解决方案问题,但我无法修复它。
我的JSON:
{
"estado": 1,
"usuarios": [
{
"nombre": "as",
"id_usuario": "34",
"huella_string": "1"
},
{
"nombre": "ded",
"id_usuario": "35",
"huella_string": "1"
},
{
"nombre": "sa",
"id_usuario": "36",
"huella_string": "1"
},
{
"nombre": "xz",
"id_usuario": "12",
"huella_string": "1"
},
{
"nombre": "asas,
"id_usuario": "28",
"huella_string": "1"
},
{
"nombre": "asscass",
"id_usuario": "7",
"huella_string": "mspZVoOalsE9QQsrwkQBBSS/PoEMo8BCAQmiLS/BC5YuKYEVicJIQQkTQlFBCxDES4EPFbE+wQI0UkqBDYW5KYEIKEs6QQmaTzYBEZEjGQEV7qxYAQaczhfBDeQaTEEGH8M0AQelrk0BDCVMK4EOlk8owRGHLTwBBqM8EUEd3CgQwQ/dCUSBAxrEJsEJpcgcATU3NT4BBK5ECgEEzpcJwQXloBIBD2UOIkELfJM4AQmKyFcBDI8QV8EDlU9ZAQ2GKl6BBhlWxJAFXdCyBwANWFxldQwbJCgpJiMjIiMADVZZZXYPICgsLCgkIiIjAAxcX2Z2DBghJSYlIyIiAA1WWWZ0FCMqLS0nIyMiJAAMYWNpdQkTHCEjIiAgHwANVltmAholKi0sJiMiIiUADGhpb3cHEBkdICAdHBwADFZcag0hKCssKSUhISEADGlscXcHDxYbHR0bGxoADFRYYBkkKiopJSIdHB0ADGtucncGDhUaHBsaGhsADVRXTCsoKigmIyAcGh0pAAxsb3MBCA8WGhsbGhscAAxUVU42KCYlIyEdGhccAAtwcnUCCRAWGhsaGhsADFdWUz0kIiIhIBwaFx0BC3V3BAkRFhkbGxscAAtXV1dfGhobGhoWEgwBCnYBBAkPFRobGxsADGxgXm4KERISEA0LCgsDCQQIDxUZHBwBC3FkbwULDQwLCAYE"
}
],
"peticion": "seleccion_usuarios"
}
这些都是我的课:
class JsonParser
{
public int estado { set; get; }
public string peticion { set; get; }
public user usuarios { set; get; }
public class user
{
public string id_usuario { set; get; }
public string huella_string { set; get; }
public string nombre { set; get; }
}
}
而且that's我如何调用数组的
var Json = JsonConvert.DeserializeObject<JsonParser>(strJSON);
ShowHintInfo(Json.usuarios.id_usuario);
感谢
的一个值
非常感谢,我用列表也工作。 –
这是正确的做法! –