cpjamloki
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2015
02:18 AM
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.
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.
{"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 8

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2015
02:48 AM
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.
cpjamloki
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2015
03:21 AM
Re: convert AA to string for AsyncPostFromString(param)
thanks komag for reply.
it will be my pleasure if you share some example.
it will be my pleasure if you share some example.
cpjamloki
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2015
03:47 AM
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 .

Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2015
05:52 AM
Re: convert AA to string for AsyncPostFromString(param)
It may not work if there are types of values it doesn't like:
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)
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)


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2015
10:38 AM
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 = invalidprior 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"}
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2015
03:18 PM
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?
cpjamloki
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015
01:58 AM
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
Need same as unanswered post.
viewtopic.php?f=34&t=64647&sid=988df4e8559d24ee1b525b7f17590cc82


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015
01:49 PM
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. 😉