Forum Discussion

cpjamloki's avatar
cpjamloki
Visitor
10 years ago

convert AA to string for AsyncPostFromString(param)

By using AsyncPostFromString(param) i want to post some data , But for http post request i have to set parameter as string and i have parameter as below in AA format.


{"abc":{"xyz":false,"ur":{"contractAcceptanceMedium":"WEB"}},"aa":{"soapRequest":{"customerSearch":{"vv":{"Address1":"NTAwIEUgRnJhbmtsaW4gU3Q=","unitNumber":"NzY0Mg==","zipCode":"MjMyMTk="},"sessionId":""}}},"selectCRequest":{"ff":{"sessionId":"","searchSelectionChoice":{}}},"queryBadDebtRestRequest":{"soapRequest":{"sessionId":"","firstName":null,"lastName":null,"emailAddress":null,"socialSecurityNumber":null,"Number":null,"creditCheckConsent":false},"doB":null}}



So i want to know that how i can convert my data in string format here? is there any function or by using concatination i should convert it? please share your views.

Thanks in advance.

8 Replies

  • I use FormatJson() and ParseJson() to translate back and forth from associative array and string, works great.
  • thanks komag for reply.
    it will be my pleasure if you share some example.
  • first = {"verifyAgentProfileRestRequest":{"isDevice":false,"soapRequest":{"contractAcceptanceMedium":"WEB"}},"searchCustomerProfileRestRequest":{"soapRequest":{"customerSearch":{"address":{"streetAddress1":"NTAwIEUgRnJhbmtsaW4gU3Q=","unitNumber":"NzY0Mg==","zipCode":"MjMyMTk="},"sessionId":""}}},"selectCustomerProfileRestRequest":{"soapRequest":{"sessionId":"","searchSelectionChoice":{}}},"queryBadDebtRestRequest":{"soapRequest":{"sessionId":"","firstName":null,"lastName":null,"emailAddress":null,"socialSecurityNumber":null,"telephoneNumber":null,"creditCheckConsent":false},"dateOfBirth":null}}

    firststr = FormatJson(first,0)
    print"firststr =" firststr

    it's giving syntax error here .
  • It may not work if there are types of values it doesn't like:

    7.20 FormatJson(json as Object, flags = 0 as Integer) as String
    Formats an Associative Array as a JSON string.
    Data types supported are booleans, integer and floating point numbers, strings, roArray, and roAssociativeArray objects.
    An error will be returned if arrays/associative arrays are nested more than 256 levels deep.
    If an error occurs an empty string will be returned.
    Normally non-ASCII characters are escaped in the output string as "\uXXXX" where XXXX is the hexadecimal representation of the Unicode character value. If flags=1, non-ASCII characters are not escaped.

    The main thing is all the values can only be Booleans, Integers, Floats, Strings, Arrays, and Associative Arrays. No Function names allowed for one thing, and perhaps other things as well. So maybe this approach won't work in your case.

    When I use it I don't use the flag, just FormatJson(myThing), not sure how that flag works anyway.

    You might try:
    print "firststr Type is " type(firststr)
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "cpjamloki" wrote:
    first = {"firstName":null,"lastName":null,"emailAddress":null,"socialSecurityNumber":null,"telephoneNumber":null,"creditCheckConsent":false},"dateOfBirth":null}}

    firststr = FormatJson(first,0)
    print"firststr =" firststr

    it's giving syntax error here .


    The BrightScript associative array literal format isn't compatible with an arbitrary JSON value.
    For one thing, the assignment to first refers to null which is not an intrinsic BrightScript keyword.

    You could do:
        null = invalid
    prior to assigning to first, to address that.

    However, in the current firmware (6.2), BrightScript also doesn't support quoting the key names, so it still won't work.

    E.g. you can do:
        first = {a:"b"}


    but you can't do:
        first = {"a":"b"}
  • "RokuKC" wrote:
    However, in the current firmware (6.2), BrightScript also doesn't support quoting the key names, so it still won't work.

    <prick up ears> What-what? Am i hearing an enhancement of hash literals is coming?
  • RokuKC's avatar
    RokuKC
    Roku Employee
    "EnTerr" wrote:
    <prick up ears> What-what?


    Ha ha, I hadn't seen that thread, but it seems like a reasonable request to me. 😉