Question : How to use datacontractserialization

I get the following string from google

{"responseData": {"language":"en","isReliable":false,"confidence":0.38233778}, "responseDetails": null, "responseStatus": 200}

 Could you please show me how to use the datacontractserialization in VB.net to get out all the properties.

Answer : How to use datacontractserialization

1) You need fore knowledge about the business object, in order to define properties that can be filled by the DataContractJsonSerializer from a JSON string.

2) It can be difficult sometimes to infer what the properties are from the string.

3) If it is available, I always suggest looking at the documentation for the API, web service, etc.

4) This process is case-sensitive, so the property names need to match the case for the properties in the JSON string.

4) Here is my take on a class that be built from that JSON string:

        Dim json As String = "{""responseData"": {""language"":""en"",""isReliable"":false,""confidence"":0.38233778}, ""responseDetails"": null, ""responseStatus"": 200}"

        Dim response As GoogleResponse = JsonObjectSerializer.Deserialize(Of GoogleResponse)(json)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
    Public Class GoogleResponse

        Public Property responseData As GoogleResponseData
        Public Property responseDetails As String
        Public Property responseStatus As String

        Public Class GoogleResponseData
            Public Property language As String
            Public Property isReliable As Boolean
            Public Property confidence As Decimal
        End Class

    End Class
Random Solutions  
 
programming4us programming4us