0
私はやや難しい作業をしています。私はここに私のコードはVB.NET現在のJSONオブジェクトを逆シリアル化できません
Public Class Rootobject
Public Property TextureAtlas As List(Of Subtexture)
End Class
Public Class Textureatlas
Public Property SubTexture() As Subtexture
Public Property _imagePath As String
End Class
Public Class Subtexture
Public Property _name As String
Public Property _x As String
Public Property _y As String
Public Property _width As String
Public Property _height As String
End Class
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim deserialized = JsonConvert.DeserializeObject(Of Rootobject)(RichTextBox1.Text.ToString())
For Each item In deserialized.TextureAtlas
MsgBox(item._name)
Next
だここでエラーがこれがJSONである
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[XMLPrasers.Form1+Subtexture]' because the type requires a JSON array (e.g.
だが、私は現在のJSONオブジェクトエラーをデシリアライズすることはできません
を得続けるいくつかのJSONの情報を取得しようとしています
{
"TextureAtlas": {
"SubTexture": [
{
"_name": "AFKClick",
"_x": "0",
"_y": "0",
"_width": "82",
"_height": "82"
},
{
"_name": "AFKDef",
"_x": "84",
"_y": "0",
"_width": "82",
"_height": "82"
},
{
"_name": "AFKHover",
"_x": "168",
"_y": "0",
"_width": "82",
"_height": "82"
},
{
"_name": "BagClick",
"_x": "0",
"_y": "84",
"_width": "82",
"_height": "82"
},
{
"_name": "BagDef",
"_x": "84",
"_y": "84",
"_width": "82",
"_height": "82"
},
{
"_name": "BagHover",
"_x": "0",
"_y": "168",
"_width": "82",
"_height": "82"
},
{
"_name": "PetClick",
"_x": "84",
"_y": "168",
"_width": "82",
"_height": "82"
},
{
"_name": "PetDef",
"_x": "168",
"_y": "84",
"_width": "82",
"_height": "82"
},
{
"_name": "PetHover",
"_x": "168",
"_y": "168",
"_width": "82",
"_height": "82"
},
{
"_name": "ShopClick",
"_x": "252",
"_y": "0",
"_width": "82",
"_height": "82"
},
{
"_name": "ShopDef",
"_x": "252",
"_y": "84",
"_width": "82",
"_height": "82"
},
{
"_name": "ShopHover",
"_x": "336",
"_y": "0",
"_width": "82",
"_height": "82"
},
{
"_name": "TwitterClick",
"_x": "252",
"_y": "168",
"_width": "82",
"_height": "82"
},
{
"_name": "TwitterDef",
"_x": "336",
"_y": "84",
"_width": "82",
"_height": "82"
},
{
"_name": "TwitterHover",
"_x": "420",
"_y": "0",
"_width": "82",
"_height": "82"
}
],
"_imagePath": "Button.png"
}
}
クラスが間違っています。ルートオブジェクトは、JSONに多数ある場合は、 'Public Property TextureAtlas As TextureAtlas'でなければなりません。' RootObjects'(bad name)のリストまたは配列にデシリアライズしてください。また、 'TextureAtlas.SubTexture'はリストまたは配列でなければなりません。残りのエラーメッセージは、配列とリストの不一致を示しています。 – Plutonix