Your Digital Media Has Never Looked So Good

 
ramim94
Topic Author
Posts: 4
Joined: Wed May 08, 2019 11:58 am

JSON key with special Character($)

Mon Jun 03, 2019 8:24 am

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 :) 
 
destruk
Posts: 2720
Joined: Sat Dec 18, 2010 4:58 pm

Re: JSON key with special Character($)

Mon Jun 03, 2019 8:33 am

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

 
destruk
Posts: 2720
Joined: Sat Dec 18, 2010 4:58 pm

Re: JSON key with special Character($)

Mon Jun 03, 2019 8:35 am

Or you can probably try
gridposter.category = video.category["$nCat"]
 
ramim94
Topic Author
Posts: 4
Joined: Wed May 08, 2019 11:58 am

Re: JSON key with special Character($)

Mon Jun 03, 2019 8:49 am

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


worked for me.
 
destruk
Posts: 2720
Joined: Sat Dec 18, 2010 4:58 pm

Re: JSON key with special Character($)

Tue Jun 04, 2019 8:00 am

 cool

Who is online

Users browsing this forum: No registered users and 12 guests