Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用VB在ASP.NET中序列化JSON_Asp.net_Json_Vb.net - Fatal编程技术网

用VB在ASP.NET中序列化JSON

用VB在ASP.NET中序列化JSON,asp.net,json,vb.net,Asp.net,Json,Vb.net,我在ASP.NET中使用VB,我一直在尝试从WebService(webmethod)序列化下面的JSON。plz可以帮助我精确的使用属性 { "api_version" : 4 , "hotel_ids" : [97497], "start_date" : "2013-07-01", "end_date" : "2013-07-03", "num_adults" : 2, "num_rooms" : 1, "currency" : "US

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

{
    "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"
                                    ]
                            }
                    }
            }
        ]
}
使用如下代码: 这是我的实体类

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