0

I'm trying to create this JSON string but having problem creating it. I'm getting System.NullReferenceException error.

Here is the json string that I would like to create

{"id":["1","2","3","4"]},"sid":["s1","s2","s3","s4"]} 

Here is the code I have so far.

Imports System.Web.Services
Imports System.Data

Partial Class test_sidetab
    Inherits System.Web.UI.Page

    <WebMethod()> Public Shared Function getfav() As String
        Dim fav As New Favorites()
        Dim js As New System.Web.Script.Serialization.JavaScriptSerializer()
            Dim i As Integer = 1
            While i < 10
                fav.id.Add(i.ToString)
                fav.sid.Add("s"+i.ToString)
                i += 1
            End While
        Dim str As String = js.Serialize(fav)
        Return str
    End Function
End Class
Public Class Favorites

    Public id As ArrayList, sid As ArrayList

End Class
0

1 Answer 1

1

fav.id is null. You need to put an ArrayList into it by writing Public id As New ArrayList (or, better yet, List(Of String))

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

Comments

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.