-->

How do I construct and pass raw json data with okH

2020-08-01 06:19发布

问题:

I am using a query where I need to POST to an endpoint with okhttpclient. The issue is I have the payload value and the senttime. I just don't know how to create a json object to send over as a raw body object to the endpoint. To make things more clear: here's my postman screenshot: enter image description here

This is my post request : https://example.org/api/service-profile/v1/device-notification/{deviceId} Now I am planning to pass {deviceId} in the path, authorization token in the header and finally , as raw payload query like this in the body :

    {
      "payload": {"notificationID":"677291f5-a784-43df-af2e-0363a4067e9c","title":"test 223","body":"payload","lockScreenVisibility":1,"groupMessage":"","fromProjectNumber":"819539062812","priority":5,"rawPayload":"{\"google.delivered_priority\":\"normal\",\"google.sent_time\":1591849563191,\"google.ttl\":259200,\"google.original_priority\":\"normal\",\"custom\":\"{\\\"i\\\":\\\"677291f5-a784-43df-af2e-0363a4067e9c\\\"}\",\"oth_chnl\":\"\",\"pri\":\"5\",\"abc\":\"1\",\"from\":\"819539062812\",\"alert\":\"payload\",\"title\":\"test 223\",\"grp_msg\":\"\",\"google.message_id\":\"0:1591849563205759%409ebbcaf9fd7ecd\",\"google.c.sender.id\":\"819539062812\",\"notificationId\":-1451117355}"}
    ,
      "sentTime": 1591849563191
    }

trouble is I have the payload value and senttime, but I dont know how to construct a json object such that i can create the structure as { "payload" :pass in my payload value, "senttime":pass in sent time} and then pass it as a raw body param over okhttpclient? Any idea how to accomplish this?

Thanks!