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
fav.idis null. You need to put anArrayListinto it by writingPublic id As New ArrayList(or, better yet,List(Of String))