Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
cpjamloki
Level 7

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.
0 Kudos
8 Replies
Komag
Level 9

Re: convert AA to string for AsyncPostFromString(param)

I use FormatJson() and ParseJson() to translate back and forth from associative array and string, works great.
0 Kudos
cpjamloki
Level 7

Re: convert AA to string for AsyncPostFromString(param)

thanks komag for reply.
it will be my pleasure if you share some example.
0 Kudos
cpjamloki
Level 7

Re: convert AA to string for AsyncPostFromString(param)

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 .
0 Kudos
Komag
Level 9

Re: convert AA to string for AsyncPostFromString(param)

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)
0 Kudos
Roku Employee
Roku Employee

Re: convert AA to string for AsyncPostFromString(param)

"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"}
0 Kudos
EnTerr
Level 9

Re: convert AA to string for AsyncPostFromString(param)

"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?
0 Kudos
cpjamloki
Level 7

send JSON as part of a post request?

is Roku support to post json data? how do I send JSON as part of a post request?
Need same as unanswered post.

viewtopic.php?f=34&t=64647&sid=988df4e8559d24ee1b525b7f17590cc82
0 Kudos
Roku Employee
Roku Employee

Re: convert AA to string for AsyncPostFromString(param)

"EnTerr" wrote:
<prick up ears> What-what?


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