を解析する:失敗は、私はこのようなJSON持つJSON
{
"myClass1" : [
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
}
],
"myClass2" : {
"1" : [
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
}
],
"2" : [
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
}
],
"3" : [
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
},
{
"field1" : "value",
"field2" : "value",
"field3" : "value"
}
]
}
}
とクラス:
class myClass1
{
public string field1 { get; set; }
public string field2 { get; set; }
public string field3 { get; set; }
}
class myClass2
{
public string field1 { get; set; }
public string field2 { get; set; }
public string field3 { get; set; }
}
class Parser
{
public myClass1[] object1 { get; set; }
public myClass2[,] object2 { get; set; }
}
そしてNewtonSoft JSONパーサーを使用して、私は(と第二のクラスを解析することはできません私は問題はありません!)私はmyClass2 [](明らかに間違っています)myClass2 [、]とmyClass2 [] []を試しましたが、何も働いていませんでした。私は間違っているの?
Newtonsoft.Json.JsonSerializationException occurred
HResult=0x80131500 Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'CreativaTV.Soporte[][]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'soportes.2', line 185, position 12. Source=Newtonsoft.Json StackTrace: at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at CreativaTV.Form1.CargarContenido() in C:\AppDev\CreativaTV\CreativaTV\CreativaTV\Form1.cs:line 61 at CreativaTV.Form1.Form1_Load(Object sender, EventArgs e) in C:\AppDev\CreativaTV\CreativaTV\CreativaTV\Form1.cs:line 32 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
次のエラーメッセージのどの部分を理解していませんか? – SLaks
私はCreativaTV.Soporte [] [] 'が表示されているコードのどこにも表示されません(コードとエラーは同じコードからのもので、名前は付けられていないはずです)。 – crashmstr