locked
JASON CLASS ... going down the path... RRS feed

  • Question

  • User2768153 posted

    in vb.net I have a controller...

    <System.Web.Http.HttpPost> Public Function PostValue(<FromBody()> ByVal value As Rootobject) As Object

    once i captured the json payload, I created a class to store the data:

    I can get the responseid by :  Dim R_ID as string = value.responseId

    How do I get the displayName from class intent???

    Thank you!

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

    Public Class Rootobject
    <JsonProperty("responseId")> Public Property responseId As String
    <JsonProperty("queryResult")> Public Property queryResult As String
    <JsonProperty("webhookStatus")> Public Property webhookStatus As String
    End Class

    Public Class Queryresult
    Inherits Rootobject
    <JsonProperty("queryText")> Public Property queryText As String
    <JsonProperty("action")> Public Property action As String
    <JsonProperty("parameters")> Public Property parameters As String
    <JsonProperty("allRequiredParamsPresent")> Public Property allRequiredParamsPresent As String
    <JsonProperty("fulfillmentText")> Public Property fulfillmentText As String
    <JsonProperty("fulfillmentMessages")> Public Property fulfillmentMessages() As Fulfillmentmessage
    <JsonProperty("intent")> Public Property intent As Intent
    <JsonProperty("intentDetectionConfidence")> Public Property intentDetectionConfidence As Integer
    <JsonProperty("diagnosticInfo")> Public Property diagnosticInfo As Diagnosticinfo
    <JsonProperty("languageCode")> Public Property languageCode As String
    End Class

    Public Class Parameters
    End Class

    Public Class Intent
    Inherits Queryresult
    <JsonProperty("name")> Public Property name As String
    <JsonProperty("displayName")> Public Property displayName As String
    End Class

    Public Class Diagnosticinfo
    Inherits Queryresult
    <JsonProperty("webhook_latency_ms")> Public Property displayName As Integer
    End Class

    Friday, February 16, 2018 3:35 PM

Answers

  • User475983607 posted

    I also thought the dotted approach would work - but not shown in intellisense.

    I see value.queryresult  - that is all.  Adding anything after it like::

    value.queryResult.queryText  generates an error : value.queryResult.queryText is not a member of string..

    It looks like a bug in the object model.  you've defined value.queryResult as a string.  I imagine you really want this.

    Public Class Rootobject
    	<JsonProperty("responseId")> Public Property responseId As String
    	<JsonProperty("queryResult")> Public Property queryResult As Queryresult
    	<JsonProperty("webhookStatus")> Public Property webhookStatus As String
    End Class

    This is a case of carefully reading the error message and reviewing the code.  Also if start using the Visual Studio debugger as suggested, this type of simple mistake is very easy to find.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 16, 2018 4:38 PM

All replies

  • User475983607 posted

    Use dot syntax to access the object members.

    value.queryResult.intent.displayName 

    Also, take some time to learn how to use the Visual Studio debugger and the watch window (or just cursor over) as it will allow you to drill into the object.  

    https://docs.microsoft.com/en-us/visualstudio/debugger/getting-started-with-the-debugger

    And it is JSON not JASON...

    Friday, February 16, 2018 4:11 PM
  • User2768153 posted

    I also thought the dotted approach would work - but not shown in intellisense.

    I see value.queryresult  - that is all.  Adding anything after it like::

    value.queryResult.queryText  generates an error : value.queryResult.queryText is not a member of string..

    Friday, February 16, 2018 4:16 PM
  • User475983607 posted

    I also thought the dotted approach would work - but not shown in intellisense.

    I see value.queryresult  - that is all.  Adding anything after it like::

    value.queryResult.queryText  generates an error : value.queryResult.queryText is not a member of string..

    It looks like a bug in the object model.  you've defined value.queryResult as a string.  I imagine you really want this.

    Public Class Rootobject
    	<JsonProperty("responseId")> Public Property responseId As String
    	<JsonProperty("queryResult")> Public Property queryResult As Queryresult
    	<JsonProperty("webhookStatus")> Public Property webhookStatus As String
    End Class

    This is a case of carefully reading the error message and reviewing the code.  Also if start using the Visual Studio debugger as suggested, this type of simple mistake is very easy to find.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 16, 2018 4:38 PM