誰かが以下のjson応答を非直列化するスクリプトで私を助けてくれますか?私が含まれている変数とその値asp.netのjson配列応答の非直列化vb
{
"results":[
{
"bulkId":"80664c0c-e1ca-414d-806a-5caf146463df",
"messageId":"bcfb828b-7df9-4e7b-8715-f34f5c61271a",
"to":"41793026731",
"sentAt":"2015-02-12T09:51:43.123+0100",
"doneAt":"2015-02-12T09:51:43.127+0100",
"smsCount":1,
"mccMnc": "22801",
"price":{
"pricePerMessage":0.01,
"currency":"EUR"
},
"callbackData": "User defined data.",
"status":{
"groupId":3,
"groupName":"DELIVERED",
"id":5,
"name":"DELIVERED_TO_HANDSET",
"description":"Message delivered to handset"
},
"error":{
"groupId":0,
"groupName":"OK",
"id":0,
"name":"NO_ERROR",
"description":"No Error",
"permanent":false
}
},
{
"bulkId":"08fe4407-c48f-4d4b-a2f4-9ff583c985b8",
"messageId":"12db39c3-7822-4e72-a3ec-c87442c0ffc5",
"to":"41793026727",
"sentAt":"2015-02-12T09:50:22.221+0100",
"doneAt":"2015-02-12T09:50:22.232+0100",
"smsCount":1,
"mccMnc": "22801",
"price":{
"pricePerMessage":0.01,
"currency":"EUR"
},
"callbackData": "reset_password",
"status":{
"groupId":3,
"groupName":"DELIVERED",
"id":5,
"name":"DELIVERED_TO_HANDSET",
"description":"Message delivered to handset"
},
"error":{
"groupId":0,
"groupName":"OK",
"id":0,
"name":"NO_ERROR",
"description":"No Error",
"permanent":false
}
}
]
}
これは新しいコード <% @ページ言語=「VB」デバッグのインポート名前空間= "システム@ =「真」%>は <%でアクセスするようになります。システム」%> < "インポート名前空間= @%> <%" System.net.mail "インポート名前空間@%> <% =" System.Data Data.SqlClient "インポート名前空間= @%> <%" %@ Import名前空間= "System.Net"%> <%@ Import名前空間= "System.Net.http"%>インポート名前空間= "System.Textの" %> <% @ = "System.Runtime.Serialization.Json" %> <%インポート名前空間@インポート名前空間@<% = "System.Webの" %> <% @インポート名前空間= "System.IO"%> <%@ Import namespace = "System.Web.Script.Serialization"%> <%@ Import名前空間= "RestSharp"%> <%@ Import namespace = "システム。 Collections.Generic」%> <%の@インポート名前空間= "System.Linqの" %> <% @インポート名前空間= "Newtonsoft.Json.Linq" %>
<SCRIPT language="vb" runat="server">
''' <summary>
''' JSON Serialization and Deserialization Assistant Class
''' </summary>
パブリック・クラスの価格は
Public Property pricePerMessage As Double
Public Property currency As String
End Class
Public Class Status
Public Property groupId As Integer
Public Property groupName As String
Public Property id As Integer
Public Property name As String
Public Property description As String
End Class
Public Class ErrorModel
Public Property groupId As Integer
Public Property groupName As String
Public Property id As Integer
Public Property name As String
Public Property description As String
Public Property permanent As Boolean
End Class
Public Class Result
Public Property bulkId As String
Public Property messageId As String
Public Property to As String
Public Property sentAt As DateTime
Public Property doneAt As DateTime
Public Property smsCount As Integer
Public Property mccMnc As String
Public Property price As Price
Public Property callbackData As String
Public Property status As Status
Public Property error As ErrorModel
End Class
Public Class Response
Public Property results As Result()
End Class
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim json = "{""results"": [{""bulkId"":""1454508683222745512"",""messageId"":""fbaa8cbd-62a2-4cdd-92a3-ebc962586356"",""to"":""2348166734353"",""sentAt"":""2016-02-03T14:11:24.509+0000"",""doneAt"":""2016-02-05T14:11:30.017+0000"",""smsCount"":1,""price"":{""pricePerMessage"":1.2500000000,""currency"":""NGN""},""status"":{""groupId"":4,""groupName"":""EXPIRED"",""id"":15,""name"":""EXPIRED_EXPIRED"",""description"":""Message expired""},""error"":{""groupId"":1,""groupName"":""HANDSET_ERRORS"",""id"":27,""name"":""EC_ABSENT_SUBSCRIBER"",""description"":""Absent Subscriber"",""permanent"":false}}]}"
Dim response As Response = JsonConvert.DeserializeObject(Of Response)(json);
Dim bulkId As String = response.Results(0).bulkId
Response.Write(bulkId)
End Sub
</SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form runat="server">
</form>
</body>
</html>
json
が応答をありがとう変数に格納されています。このエラーが発生しました:行35を強調表示します。コンパイラエラーメッセージ:BC30183:キーワードが識別子として有効ではありません。 ソースエラー: ライン33:エンドクラス 34行目: ライン35:パブリッククラスエラー – Popeは予約語との競合に名前を付けるように見えます。私はクラスとプロパティを更新しました。それが今働くかどうか確認してください – Nkosi
ええ。ありがとう。 「PublicプロパティをAs Stringに」強調表示「to1」に変数名を変更しようとしましたが、エラーはそのまま残ります。私は上記のように完全なテストコードを追加しました。親切なアドバイス – Pope