Reputation: 53
I am getting the following error:
End of statement expected
Code:
<%@ Page Language="VB" Debug = "true" ContentType="text/html" ResponseEncoding="iso-8859-1"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.net.mail"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.http" %>
<%@ Import Namespace="System.text" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="microsoft.http" %>
<%@ Import namespace="System.Web.Script.Serialization" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Runtime.Serialization.Json" %>
<%@ Import Namespace="System.ServiceModel.Web" %>
<%@ Import Namespace="RestSharp" %>
<%@ Import namespace="System.Web.HttpResponse"%>
<%@ Import namespace ="System.Threading.Tasks" %>
<%@ Import namespace ="System.Net.Http.Headers" %>
<%@ Import namespace= "System.Collections.Generic" %>
<%@ Import namespace ="System.Linq" %>
<%@ Import namespace ="Newtonsoft.Json.Linq" %>
<SCRIPT language="vb" runat="server">
Sub Page_load(S as Object,E as EventArgs)
Dim json As String = "{""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}}]}"
' parsing
Dim sb As New StringBuilder()
Dim o As JObject = JObject.Parse(json)
For Each prop As JProperty In o("results").Children(Of JProperty)()
Dim lresult As JObject = DirectCast(prop.Value, JObject)
sb.AppendFormat("<img src='{0}' alt='{1}' />" & vbCr & vbLf, lresult("to"), lresult("doneAt"))
result.text + = sb.tostring ()'(lresult("tod"))
Next
result.text=sb.ToString()
end sub
</SCRIPT>
<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">
<asp:Label ID="result" runat="server" />
</form>
</body>
</html>
Upvotes: 0
Views: 131
Reputation: 350252
This line is not valid:
Dim json As String = "{"results": [{"bulkId":"1454508683222745512","messageId":"fbaa...
... because the double quotes you open are closed two characters later, and then results
is invalid syntax. Instead you need to escape the quotes that are part of the JSON, by doubling them:
Dim json As String = "{""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}}]}"
Note how the syntax highlighting also gives a clue. Copy that corrected line back into your code.
If you have other cases like that, it is probably the best to take the JSON string into another empty document and replace all double quotes by two of them with a global find/replace operation. Then copy it back into your code. That is what I did to get the above string.
Upvotes: 1