Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 892
  • Last Modified:

asp .net json deserialize

hi i have a json string ("see json a") - code below

in asp .net I use JavaScriptSerializer to get the data (see asp A) - code below

everthing works fine but i would like to add additional data into "conversationhistory" for example ( see json B)  - code below and be able to parse though only 'conversationhistory"  on the server

maybe move it to an array??

any help would be appeciated - thanks in advance








json A

{ "name": "bill", "profileimage": "bill_pic.jpg", "timestamp": "11/24/2010 2:07:25 PM", "subject": "Re: org subject", "msg": "hello this is a message", "conversationhistory": [{ "id": "1", "ch_name": "frank", ch_"profileimage": "frank_pic.jpg", "ch_timestamp": "11/24/2010 9:17:52 AM", "ch_msg": "hello this is a test back" }] }

------------------------------------------------------------------------------------------

asp code A
Dim json As New JavaScriptSerializer()
Dim p2 As ReplyMsgInfo = json.Deserialize(Of ReplyMsgInfo)(jsondata)

Public Class ReplyMsgInfo

        Private _msg As String
        Public Property msg() As String
            Get
                Return _msg
            End Get
            Set(ByVal value As String)
                _msg = value
            End Set
        End Property
End class

-----------------------------------------------------------------------------------------

json B

{ "name": "bill", "profileimage": "bill_pic.jpg", "timestamp": "11/24/2010 2:07:25 PM", "subject": "Re: org subject", "msg": "hello this is a message", "conversationhistory": [{ "id": "1", "ch_name": "frank", "ch_profileimage": "frank_pic.jpg", "ch_timestamp": "11/24/2010 9:17:52 AM", "ch_msg": "hello this is a test back from frank" }
{ "id": "2", "ch_name": "joe", "ch_profileimage": "joe_pic.jpg", "ch_timestamp": "11/24/2010 10:17:52 AM", "ch_msg": "hello this is a test back from joe" }] }

Open in new window

0
doctor069
Asked:
doctor069
  • 2
1 Solution
 
Swapnil PipariaArchitectCommented:
you get list of object by.

Dim json As New JavaScriptSerializer()
Dim p2 As List(of Object) = json.Deserialize(Of ReplyMsgInfo)(jsondata)

Public Class ReplyMsgInfo

        Private _msg As String
        Public Property msg() As String
            Get
                Return _msg
            End Get
            Set(ByVal value As String)
                _msg = value
            End Set
        End Property
End class
0
 
doctor069Author Commented:
The post by netswap was not helpful. It was basically just a code and paste of some of my code in the question. I would not use it as an answer
0
 
Swapnil PipariaArchitectCommented:
Hi Doctor069,

       Have you check my code snippet? I have modified the highlighted line in your code as a suggestion to solve your problem.

Dim json As New JavaScriptSerializer()
Dim p2 As List(of Object) = json.Deserialize(Of ReplyMsgInfo)(jsondata)

Public Class ReplyMsgInfo

        Private _msg As String
        Public Property msg() As String
            Get
                Return _msg
            End Get
            Set(ByVal value As String)
                _msg = value
            End Set
        End Property
End class

Thanks,
Netswap.
0
 
ModernMattCommented:
No response to Expert and Moderator requests; re-starting the close process as recommended by the CV.

ModernMatt
Experts Exchange Moderator
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now