Results 1 to 4 of 4

Thread: How to encode an array in json?

  1. #1

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    How to encode an array in json?

    Hi there,


    I'm a bit rusty with vb.net and I need your help for encoding this:

    Code:
    {"monday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"tuesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"wednesday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"thursday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"friday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"saturday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]},"sunday":{"start":"09:00","end":"18:00","breaks":[{"start":"11:20","end":"11:30"},{"start":"14:30","end":"15:00"}]}}
    in json format in vb.net, how you can see this string is already decoded in json but I want know how I can create an array or something like for store the days with the break time. Essentially:

    Code:
    "monday":{
    "start":"09:00",
    "end":"18:00",
    "breaks":[
    {
    "start":"11:20",
    "end":"11:30"
    },
    {
    "start":"14:30",
    "end":"15:00"
    }
    ]
    },
    "tuesday":{
    "start":"09:00",
    "end":"18:00",
    "breaks":[
    {
    "start":"11:20",
    "end":"11:30"
    },
    {
    "start":"14:30",
    "end":"15:00"
    }
    ]
    },
    Someone could help me to create the array with this contents and convert it into json? Thanks.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to encode an array in json?

    When I create web methods in VB I use Dictionary(Of String, String) for a JSON OBJECT and IList(of String) for a JSON ARRAY.

    If the ARRAY is an array of objects then it's an IList(Of Dictionary(Of String, String)).

    Kind of like this:

    Code:
    <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
        Public Function CtrlService(ByVal ctrloption As String, ByVal ctrlval1 As String _
                                   , ByVal ctrlval2 As String _
                                   , ByVal ctrlval3 As String _
                                   , ByVal ctrlextra As Dictionary(Of String, String) _
                                   , ByVal username As String _
                                   , ByVal sguid As String _
                                   , ByVal source As IList(Of Dictionary(Of String, String))) As String

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Re: How to encode an array in json?

    Quote Originally Posted by szlamany View Post
    When I create web methods in VB I use Dictionary(Of String, String) for a JSON OBJECT and IList(of String) for a JSON ARRAY.

    If the ARRAY is an array of objects then it's an IList(Of Dictionary(Of String, String)).

    Kind of like this:

    Code:
    <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
        Public Function CtrlService(ByVal ctrloption As String, ByVal ctrlval1 As String _
                                   , ByVal ctrlval2 As String _
                                   , ByVal ctrlval3 As String _
                                   , ByVal ctrlextra As Dictionary(Of String, String) _
                                   , ByVal username As String _
                                   , ByVal sguid As String _
                                   , ByVal source As IList(Of Dictionary(Of String, String))) As String
    What's WebMethod? I just want to know how I can story it in an array or dictionary is the same and made a json that's it. Thanks.

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to encode an array in json?

    Don't you represent them as datatypes in VB? I was just demonstrating what data type was a JSON ARRAY.

    Show some code so I can see how you are trying to apply this.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width