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: 
ramim94
Level 7

JSON key with special Character($)

Hi everyone, I have an API response where one of the keys in the JSON response is a $ sign. for example

response { 
...
category{
    $nCat : "something",
    $sCat : "some other things"
}
...
}


Now, when I'm trying to parse this inside a for-each loop,

for each video in allVideos
gridposter.category = video.category.$nCat
...
end for


The error is 'Syntax error: unexpected character $'

is there a way to parse this JSON? Thanks in Advance Smiley Happy 
0 Kudos
4 Replies
destruk
Level 10

Re: JSON key with special Character($)

Prior to parsing, do a string replace for the $.
temp=strreplace(readInternet,"$","z_")
Function strReplace(basestr As String,oldsub As String,newsub As String) As String
newstr=""
i=1
While i<=Len(basestr)
x=Instr(i,basestr,oldsub)
If x=0
newstr=newstr+MID(basestr,i)
Exit While
End If
If x>i
newstr=newstr+MID(basestr,i,x-i)
i=x
End If
newstr=newstr+newsub
i=i+Len(oldsub)
End While
Return newstr
End Function

0 Kudos
destruk
Level 10

Re: JSON key with special Character($)

Or you can probably try
gridposter.category = video.category["$nCat"]
0 Kudos
ramim94
Level 7

Re: JSON key with special Character($)

Thanks a lot for the quick response, i was looking through associative array methods and doing 
video.category.Lookup("$nCat")


worked for me.
0 Kudos
destruk
Level 10

Re: JSON key with special Character($)

 cool
0 Kudos