Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3273

Re: How to pass the body content which is in Json format in Rest API's Post method?

$
0
0

Hi Mohid,

 

Take a free variable of type "Text" and pass the response content into this variable, here this variable will be our response and using a custom library build your parser function for parsing this response

 

Mostly you need to use your String functionalities for Parsing and DeParsing the responses.

 

Here below is the ex for your reference

 

var response : Text;

 

if (ws_call.Code.Contains("200"))

    {

            response.content = ws_call.Content;

            var result = "YOUR PARSER LIB FUNCTION"; (Pass the response as a parameter)

     }

 

*************Lib Function Building using string functionalities************

 

var text = Response.content;

var textLen = text.Length();

 

if (!text.IsInitial())

{

    var respcode;

    var stat = text.Find("respstat");

    if (!stat.IsInitial())

    {

        var start = stat + 11;

        //var end = stat+13;

        respcode = text.Substring(start, 1);

        result = result.Concatenate(respcode) + "|";

    }

 

    var mess = text.Find("resptext");

    if (!mess.IsInitial())

    {

        var start = mess + 11;

        var end = text.Find("\"", start);

        var delimtLen = end - start;

        var resptext = text.Substring(start, delimtLen);

        result = result.Concatenate(resptext);

    }

 

    if (respcode == "A")

    {

        var token = text.Find("token");

        if (token > 0)

        {

            var start = token + 8;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

 

        var profileid = text.Find("profileid");

        if (profileid > 0)

        {

            var start = profileid + 12;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

 

        var acctid = text.Find("acctid");

        if (acctid > 0)

        {

            var start = acctid + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

 

        var amount = text.Find("amount");

        if(amount > 0)

        {

            var start = amount + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

 

        var retref = text.Find("retref");

        if (retref > 0)

        {

            var start = retref + 9;

            var end = text.Find("\"", start);

            var delimtLen = end - start;

            var resptext = text.Substring(start, delimtLen);

            result = result + "|";

            result = result.Concatenate(resptext);

        }

    }

}

 

return result;   (Result is a String of 255 chars len)

 

This will basically break you response and identifies the actual response values based on some specific tags. In the result you will have the response actual values you are looking for to fill back in actual specific fields of the BO you r designing.

 

This should work out. Basically above parsing is a example one may not be useful completely, but you have build your own parser function according to the need and your response style.

 

Thanks.

 

Regards

Hanu


Viewing all articles
Browse latest Browse all 3273

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>