0

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>
3
  • Please quote the error in your question, and the line where it occurs. Commented Feb 21, 2016 at 20:10
  • Yes, end of statement expected. i even tried to add double quotes to the end of the string, but the error message keeps coming Commented Feb 23, 2016 at 23:50
  • The statement is invalid, and you cannot fix it with just adding one double quote. See my answer on how to fix the situation. Commented Feb 24, 2016 at 5:50

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. I am trying to achieve that with a code like json=json.Replace(""",""""), but that does not seem to work
No, like I said, your code is now invalid. The code does not compile, so the replace never executes. You need to escape all the double quotes inside the string. I have updated my answer, and provide you now with the complete corrected statement. Just copy it back into your code.
I have implemented the corrected as done by Trincot, Please see the script above, but i am still not seeing the results parsed
Have you tried to debug your code? Like putting result.text+="test" at the end of your Sub to see if that is displayed? Then if it does display, but something literal in the loop as well, like result.text + = "." & sb.tostring (), and see if you get these dots... etc. I don't have the environment to test your code, so I can't really debug it myself. Your original problem was the compiling error, which I answered and think solved for you. If there is now a problem with the rest of the code, I think you will get more response if you ask that as a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.