SReject / JSON-For-Mirc

JSON parser for mIRC
19 stars 6 forks source link

Not parsing data from variable #46

Closed VitruxPT closed 6 years ago

VitruxPT commented 6 years ago

Hey,

I'm used to only parse data from urls but this time I need to parse some data from vars but it doesn't seem to be working.

I've tried with the example below:

alias test {
  var %data = {"type":"something","data":{"something":"abc11111"}}
  var %v = parseSomeJson_ $+ $ticks $+ $ctime
  JSONOpen -bd %v %data
  if (%JSONError) { return 0 }
  var %type = $json(%v,type).Value
  if (!%type) { echo 5 -s NOT FOUND | return 0 }
  return %type
  JSONClose %v
}

With this example, I always get NOT FOUND, not even $json(%v) outputs something I've also double checked if the JSON is correct and it is.

I'm using v1.0.4000 of this package.

SReject commented 6 years ago

In your /JSONOpen you are using the -b switch, indicating its from a bvar(binary variable). Remove -b switch as you are passing data in from a variable and not a bvar.

JSONOpen -d %v %data

On another note, you don't need to use both -d and JSONClose. -d closes the json handler after the script finishes execution, /JSONClose closes the json handler immediately upon being called