O
old_School
Guest
I'm having issues with casting a josn string to a object:
{"Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Collage.Domain.Models.Order.Order'."}
'Convert Json to Model
_Order = CType(JsonConvert.DeserializeObject(_JSON), Domain.Models.Order.Order)
Order Model:
Namespace Domain.Models.Order
Public Class Order
Public Property api_key As String
Public Property order_id As String
Public Property shipping_first_name As String
Public Property shipping_last_name As String
Public Property shipping_address1 As String
Public Property shipping_address2 As String
Public Property shipping_city As String
Public Property shipping_state As String
Public Property shipping_zip As String
Public Property shipping_country As String
Public Property shipping_email As String
Public Property shipping_phone As String
Public Property shipping_method As String
Public Property items As Item()
End Class
Public Class Image
Public Property page As Integer
Public Property url As String
End Class
Public Class Item
Public Property sku As String
Public Property quantity As Integer
Public Property substrate As String
Public Property diecut_shape As String
Public Property images As Image()
End Class
End Namespace
Json Code Being built to be passed in
Dim Json As String
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
oOrder.api_key = ""
oOrder.order_id = "000001"
oOrder.shipping_address1 = "123"
oOrder.shipping_address2 = "456"
oOrder.shipping_city = "Test"
oOrder.shipping_country = "US"
oOrder.shipping_email = "test@visionps.com"
oOrder.shipping_first_name = "Test"
oOrder.shipping_last_name = "User"
oOrder.shipping_method = "USPS"
oOrder.shipping_phone = "111-111-1111"
oOrder.shipping_state = "IL"
oOrder.shipping_zip = "60901"
Json = serializer.Serialize(oOrder)
Json String being passed in:
"{""api_key"":"""",""order_id"":""000001"",""shipping_first_name"":""Test"",""shipping_last_name"":""User"",""shipping_address1"":""123"",""shipping_address2"":""456"",""shipping_city"":""Test"",""shipping_state"":""IL"",""shipping_zip"":""60901"",""shipping_country"":""US"",""shipping_email"":""test@visionps.com"",""shipping_phone"":""111-111-1111"",""shipping_method"":""USPS"",""items"":null}"
Continue reading...
{"Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Collage.Domain.Models.Order.Order'."}
'Convert Json to Model
_Order = CType(JsonConvert.DeserializeObject(_JSON), Domain.Models.Order.Order)
Order Model:
Namespace Domain.Models.Order
Public Class Order
Public Property api_key As String
Public Property order_id As String
Public Property shipping_first_name As String
Public Property shipping_last_name As String
Public Property shipping_address1 As String
Public Property shipping_address2 As String
Public Property shipping_city As String
Public Property shipping_state As String
Public Property shipping_zip As String
Public Property shipping_country As String
Public Property shipping_email As String
Public Property shipping_phone As String
Public Property shipping_method As String
Public Property items As Item()
End Class
Public Class Image
Public Property page As Integer
Public Property url As String
End Class
Public Class Item
Public Property sku As String
Public Property quantity As Integer
Public Property substrate As String
Public Property diecut_shape As String
Public Property images As Image()
End Class
End Namespace
Json Code Being built to be passed in
Dim Json As String
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
oOrder.api_key = ""
oOrder.order_id = "000001"
oOrder.shipping_address1 = "123"
oOrder.shipping_address2 = "456"
oOrder.shipping_city = "Test"
oOrder.shipping_country = "US"
oOrder.shipping_email = "test@visionps.com"
oOrder.shipping_first_name = "Test"
oOrder.shipping_last_name = "User"
oOrder.shipping_method = "USPS"
oOrder.shipping_phone = "111-111-1111"
oOrder.shipping_state = "IL"
oOrder.shipping_zip = "60901"
Json = serializer.Serialize(oOrder)
Json String being passed in:
"{""api_key"":"""",""order_id"":""000001"",""shipping_first_name"":""Test"",""shipping_last_name"":""User"",""shipping_address1"":""123"",""shipping_address2"":""456"",""shipping_city"":""Test"",""shipping_state"":""IL"",""shipping_zip"":""60901"",""shipping_country"":""US"",""shipping_email"":""test@visionps.com"",""shipping_phone"":""111-111-1111"",""shipping_method"":""USPS"",""items"":null}"
Continue reading...