使用VB在ASP.NET中序列化JSON

罗勒

我在ASP.NET中使用VB,并且一直在尝试从WebService(webmethod)序列化以下JSON。请帮助我使用的确切属性。

{
    "api_version" : 4 ,
    "hotel_ids" : [97497],
    "start_date" : "2013-07-01",
    "end_date" : "2013-07-03",
    "num_adults" : 2,
    "num_rooms" : 1,
    "currency" : "USD",
    "user_country" : "US",
    "device_type" : "d",
    "query_key" : "6167a22d1f87d2028bf60a8e5e27afa7_191_1360299600000_2_2",
    "lang" : "en_US",
    "num_hotels" : 1,
    "hotels" :
        [
            {
                "hotel_id": 97497,
                "room_types":
                    {
                        "Fenway Room":
                            {
                                "url": "http: //www.partner-site.com/hotel_commonwealth/fenway_room?start_date=2013-07-01&end_date=2013-07-05&num_adults=2",
                                "price": 178.50,
                                "fees": 80,
                                "fees_at_checkout": 0,
                                "taxes": 20,
                                "taxes_at_checkout": 0,
                                "final_price": 278.50,
                                "discounts":
                                    [
                                        {
                                            "marketing_text": "10% off entire stay during July",
                                            "is_percent": true,
                                            "amount": 10,
                                            "price": 20,
                                            "fees": 0,
                                            "fees_at_checkout": 0,
                                            "taxes": 0,
                                            "taxes_at_checkout": 0,
                                            "final_price": 20
                                        },
                                        {
                                            "marketing_text": "1% off web special",
                                            "is_percent": true,
                                            "amount": 1,
                                            "price": 2,
                                            "fees": 0,
                                            "fees_at_checkout": 0,
                                            "taxes": 0,
                                            "taxes_at_checkout": 0,
                                            "final_price": 2
                                        },
                                        {
                                            "marketing_text": "Waive property fee",
                                            "is_percent": false,
                                            "amount": 25,
                                            "price": 0,
                                            "fees": 25,
                                            "fees_at_checkout": 0,
                                            "taxes": 0,
                                            "taxes_at_checkout": 0,
                                            "final_price": 25
                                        }
                                    ],
                                "currency": "USD",
                                "num_rooms": 1,
                                "room_code": "SINGLE",
                                "room_amenities":
                                    [
                                        "BREAKFAST_AND_LUNCH_INCLUDED",
                                        "ROOM_WITH_A_VIEW"
                                    ]
                            }
                    }
            }
        ]
}
拉梅什·罗丹(Ramesh Roddam)

像这样使用代码:这是我的实体类

Public Class Book

   ' autocomplete example needs "id", "value" and the "label" variables to be sent back.
   ' do not change or remove "id", "value" and the "label" variables
   Public Property id() As String
   Public Property label() As String
   Public Property value() As String

   Public Property Author() As String
   Public Property Genre() As String
   Public Property Price() As String
   Public Property Publish_date() As String
   Public Property Description() As String
End Class


Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

    '  Query string 'term' is for autocomplete. By default, it sends the variable 
    '  "term" with the search word to the backend page.
    Dim searchText As String = context.Request.QueryString("term")
    Dim books As Collection = New Collection

    Dim ds As New DataSet()
    ds.ReadXml(HttpContext.Current.Server.MapPath("jsonfile"))
    Dim dv As DataView = ds.Tables(0).DefaultView
    dv.RowFilter = [String].Format("title like '{0}*'", searchText.Replace("'", "''"))

    Dim book As Book
    For Each myDataRow As DataRowView In dv
        book = New Book()
        book.id = myDataRow("id").ToString()
        book.value = myDataRow("title").ToString()
        book.label = myDataRow("title").ToString()
        book.Author = myDataRow("author").ToString()
        book.Genre = myDataRow("genre").ToString()
        book.Price = myDataRow("price").ToString()
        book.Publish_date = myDataRow("publish_date").ToString()
        book.Description = myDataRow("description").ToString()
        books.Add(book)
    Next

    Dim serializer As JavaScriptSerializer = New JavaScriptSerializer
    Dim jsonString As String = serializer.Serialize(books)
    context.Response.Write(jsonString)

End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

VB.NET 中的 JSON 序列化技术

ASP.Net Core中的JSON序列化/反序列化

如何使用Json.net在Vb.net中反序列化JSON对象?

VB .NET JSON 反序列化

asp .net core 6 如何更新 json 序列化选项。Json 序列化中的日期格式

如何使用Newtonsoft在Vb.net中反序列化更复杂的Json Doc

使用 Asp.net MVC 序列化 Json 数组

使用 JSON.NET 在 VB.net 中反序列化 JSON 数组(我知道 - 不是数组)

Json使用ASP.NET MVC和Json.Net反序列化View中显示的输出

如何在VB.net中访问反序列化的JSON数据?

在VB.NET中反序列化嵌套JSON以进行转换

在从JSON到VB.NET的列表中反序列化

VB.NET 从 json 反序列化对象中获取键列表

使用JSON.Net反序列化器反序列化动态JSON

JSON使用.NET DataContractJsonSerializer序列化器与字典进行序列化/反序列化

反序列化Json VB.NET

VB.Net / JSON-反序列化

使用Json.net(VB.NET)序列化嵌套JSON

如何在ASP.NET Core 3中设置JSON序列化程序设置?

ASP.net Web-api中的简单类型JSON序列化

在 ASP.NET Core 视图页面中解析反序列化 JSON 数组

使用json.net反序列化JSON

JSON.NET:使用LINQ从JSON反序列化

使用JSON.NET反序列化JSON数据

使用JSON.NET序列化/反序列化动态属性名称

使属性反序列化但不使用json.net序列化

使用Json.NET对混合类型的数组进行序列化/反序列化

使用json.net对对象属性进行条件序列化/反序列化

使用 JSON.NET 反序列化和序列化字典<string, object>