Android Question json parse error

monic

Active Member
Licensed User
Longtime User
Hi,
I've search the forum so i thought i'd ask I have some json that needs phasing but the response is always different depending on queries and actions of the users. Could I use similar code to build the required maps, lists, string each time as required similar to jsontree tool inside of the android app?

B4X:
{
  "id": "398bb656-9e67-4383-85ab-d2300424fc7e",
  "timestamp": "2016-01-13T19:16:24.512Z",
  "result": {
    "source": "domains",
    "resolvedQuery": "what day is it",
    "action": "clock.date",
    "parameters": {
      "request_type": "dayofweek",
      "date": "2016-01-13T19:16:24Z"
    },
    "metadata": {},
    "fulfillment": {
      "speech": "It is Wednesday, 13 January 2016."
    }
  },
  "status": {
    "code": 200,
    "errorType": "success"
  },
  "asr": {
    "what day is it": 0.9612201
  }
}

This part changes and breaks the app as the end part chances asr.get("what day")
B4X:
Dim what day is it As Double = asr.Get("what day is it")


B4X:
Dim parser As JSONParser
parser.Initialize(example)
Dim root As Map = parser.NextObject
Dim result As Map = root.Get("result")
Dim metadata As Map = result.Get("metadata")
Dim resolvedQuery As String = result.Get("resolvedQuery")
Dim action As String = result.Get("action")
Dim source As String = result.Get("source")
Dim fulfillment As Map = result.Get("fulfillment")
Dim speech As String = fulfillment.Get("speech")
Dim parameters As Map = result.Get("parameters")
Dim date As String = parameters.Get("date")
Dim request_type As String = parameters.Get("request_type")
Dim asr As Map = root.Get("asr")
Dim what day is it As Double = asr.Get("what day is it")
Dim id As String = root.Get("id")
Dim timestamp As String = root.Get("timestamp")
Dim status As Map = root.Get("status")
Dim code As Int = status.Get("code")
Dim errorType As String = status.Get("errorType")
 
Last edited:

monic

Active Member
Licensed User
Longtime User
I just used the map function and it worked :eek: I'm learning!

B4X:
Dim usr = asr.GetKeyAt(0)
 
Upvote 0
Top