Solved

asp .net json deserialize

Posted on 2010-11-24
7
870 Views
Last Modified: 2012-05-10
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
Comment
Question by:doctor069
  • 2
7 Comments
 
LVL 16

Accepted Solution

by:
Swapnil Piparia earned 500 total points
ID: 34211484
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
 

Author Comment

by:doctor069
ID: 34410212
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
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 34410457
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
 

Expert Comment

by:ModernMatt
ID: 34440962
No response to Expert and Moderator requests; re-starting the close process as recommended by the CV.

ModernMatt
Experts Exchange Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now