Calling JSON API from Script

  • 599 Views
  • Last Post 12 January 2015
Axial-User posted this 09 January 2015

I'm writing a script to call a JSON API exposed by Blue Iris in an attempt to make camera adjustments in my scenes. I'm using this class to serialize objects into JSON notation.

class:
System.Web.Script.Serialization.JavaScriptSerializer

code:
string json = new JavaScriptSerializer().Serialize(new
{
cmd = "PTZ",
camera = "CAM1",
button = 101
});

This requires a project to have a reference to System.Web.Extensions. When I copy the .cs file over to my InControl instance, it complains that it can't compile because it can't find Script in System.Web. Thus, System.Web.Extensions is not referenced as part of the InControl project.

I thought about using reflection to load the DLL at runtime but that is such a pain since you have to invoke methods and stuff weird. Has anyone else used a script to call JSON APIs? Did you just manually write out the JSON code that needed to be sent? It's not as though I'm creating large complicated JSON objects, but I prefer serializing objects that represent what I need.

Any chance the InControl software could get updated to include a reference to System.Web.Extensions?

Order By: Standard | Newest | Votes
Ryan-Scott posted this 11 January 2015

I'm writing a script to call a JSON API exposed by Blue Iris in an attempt to make camera adjustments in my scenes. I'm using this class to serialize objects into JSON notation.

class:
System.Web.Script.Serialization.JavaScriptSerializer

code:
string json = new JavaScriptSerializer().Serialize(new
{
cmd = "PTZ",
camera = "CAM1",
button = 101
});

This requires a project to have a reference to System.Web.Extensions. When I copy the .cs file over to my InControl instance, it complains that it can't compile because it can't find Script in System.Web. Thus, System.Web.Extensions is not referenced as part of the InControl project.

I thought about using reflection to load the DLL at runtime but that is such a pain since you have to invoke methods and stuff weird. Has anyone else used a script to call JSON APIs? Did you just manually write out the JSON code that needed to be sent? It's not as though I'm creating large complicated JSON objects, but I prefer serializing objects that represent what I need.

Any chance the InControl software could get updated to include a reference to System.Web.Extensions?


This version (4.0.5489) has a reference to Newtonsoft's JSON.

Here's a sample usage:

string js = Newtonsoft.Json.JsonConvert.SerializeObject(new {
cmd = "PTZ",
camera = "CAM1",
button = 101
});

Axial-User posted this 12 January 2015

That is exactly what I needed. Thanks!

Close