Edit
I made this edit so in case anyone is in the same position as me I hopes this info will help you.
If you wan't to parse JSON and get neatly readable text you need to deserialize it.
You can use the already built in JavaScriptSerializer or you can use Newtonsoft JSON.NET .
For the JavaScriptSerializer you need to shutdown HS3 and edit the settings.ini file location in HomeSeer/Config/
Edit of add this line just before the [Display] line
ScriptingReferences=System.Web.Script.Serialization;System.W eb.Extensions.dll
For Newtonsoft you also need to shutdown HS3 and edit the settings.ini file location in HomeSeer/Config/
Edit of add this line just before the [Display] line
ScriptingReferences=Newtonsoft.Json;Newtonsoft.Json.dll
And add the Newtonsoft.Json.dll in the root directory of Homeseer. I got my Newtonsoft.Json.dll copy from /Homeseer/bin/homeseer/
If your JSON string looks like this
You can easily get each value
However If your string looks like this.
The JSON_result is wrapped in another property named "Venue"
So you need to create a class
This site let's you check you JSON string and make it more readable
https://jsonlint.com
This site creates all the public classes you JSON string needs
http://jsonutils.com
I hopes this helps someone else
------------------------------------------------------------------------------------------------------------
Original post
I've been reading a lot of topics but I still have several questions.
I want to parse a JSON string and if I'm correct there are two ways to do it
With Newtonsoft and the JavaScriptSerializer.
The Newtonsoft needs the Newtonsoft.Json.dll which is located in the /HomeSeer/bin/homeseer/ directory
The JavaScriptSerializer needs the System.Web.Extensions.dll (which you need to import yourself under /HomeSeer/bin/scripting
If you use the System.Web.Extensions.dll you need to edit your settings.ini file and add the following line
If the above info is incorrect please let me know
Ok now the questions;
When I edit the settings.ini and add the ScriptingReferences line, the line disappears after I restarted Homeseer and I don't see anything in the log.
Is this method still used and I'm I using the syntax correct?
In an other thread I see they use this line
Do I need the full path?
Can I use this under Linux (/HomeSeer/bin/Newtonsoft.Json.dll)?
If Newtonsoft is already include in Homeseer why do I need to edit the settings.ini file?
Does anyone have a working code for the Newtonsoft method (I've read that this method is a lot faster)?
I've ran this script
Then I get this error:
With this error:
I made this edit so in case anyone is in the same position as me I hopes this info will help you.
If you wan't to parse JSON and get neatly readable text you need to deserialize it.
You can use the already built in JavaScriptSerializer or you can use Newtonsoft JSON.NET .
For the JavaScriptSerializer you need to shutdown HS3 and edit the settings.ini file location in HomeSeer/Config/
Edit of add this line just before the [Display] line
ScriptingReferences=System.Web.Script.Serialization;System.W eb.Extensions.dll
For Newtonsoft you also need to shutdown HS3 and edit the settings.ini file location in HomeSeer/Config/
Edit of add this line just before the [Display] line
ScriptingReferences=Newtonsoft.Json;Newtonsoft.Json.dll
And add the Newtonsoft.Json.dll in the root directory of Homeseer. I got my Newtonsoft.Json.dll copy from /Homeseer/bin/homeseer/
If your JSON string looks like this
Code:
{ "UPTIME": "UNKNOWN", "VERSION ": 2.0, "SENDTIME": "03:33:52", "SENDDATE": "28- 12-2012", "HOSTNAME": "My-PC" }
Code:
Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Sub Main(params as object) Dim json As String Dim version As String Dim uptime As String Dim obj As New Object json = "{""UPTIME"": ""UNKNOWN"", ""VERSION"": 2.0, ""SENDTIME"": ""03:33:52"", ""SENDDATE"": ""28- 12-2012"", ""HOSTNAME"": ""My-PC""}" obj = JsonConvert.DeserializeObject(json) uptime = obj.Item("UPTIME").ToString version = obj.Item("VERSION").ToString hs.WriteLog("Thinking cleaner Status", uptime) hs.WriteLog("Thinking cleaner Status", version) end sub
HTML Code:
https://forums.homeseer.com/forum/homeseer-products-services/system-software-controllers/hs3-hs3pro-software/hs3-pro-beta-releases/85649-json-deserialize-in-hs3-scripts-solved?t=172336&highlight=json
However If your string looks like this.
Code:
{ "Venue": { "ID": 3145, "Name": "Big Venue, Clapton", "NameWithTown": "Big Venue, Clapton, London", "NameWithDestination": "Big Venue, Clapton, London", "ListingType": "A", "Address": { "Address1": "Clapton Raod", "Address2": "", "Town": "Clapton", "County": "Greater London", "Postcode": "PO1 1ST", "Country": "United Kingdom", "Region": "Europe" }, "ResponseStatus": { "ErrorCode": "200", "Message": "OK" } } }
HTML Code:
https://stackoverflow.com/questions/21676708/simple-working-example-of-json-net-in-vb-net
Code:
Public Class Container Public Venue As JSON_result End Class Public Class JSON_result Public ID As Integer Public Name As String Public NameWithTown As String Public NameWithDestination As String Public ListingType As String End Class Dim obj = JsonConvert.DeserializeObject(Of Container)(...your_json...)
This site let's you check you JSON string and make it more readable
https://jsonlint.com
This site creates all the public classes you JSON string needs
http://jsonutils.com
I hopes this helps someone else
------------------------------------------------------------------------------------------------------------
Original post
I've been reading a lot of topics but I still have several questions.
I want to parse a JSON string and if I'm correct there are two ways to do it
With Newtonsoft and the JavaScriptSerializer.
The Newtonsoft needs the Newtonsoft.Json.dll which is located in the /HomeSeer/bin/homeseer/ directory
The JavaScriptSerializer needs the System.Web.Extensions.dll (which you need to import yourself under /HomeSeer/bin/scripting
If you use the System.Web.Extensions.dll you need to edit your settings.ini file and add the following line
Code:
ScriptingReferences=System.Web.Extensions.dll
Ok now the questions;
When I edit the settings.ini and add the ScriptingReferences line, the line disappears after I restarted Homeseer and I don't see anything in the log.
Is this method still used and I'm I using the syntax correct?
In an other thread I see they use this line
Code:
ScriptingReferences=Newtonsoft.Json;C:"Program Files (x86)\HomeSeer HS3"\Bin\Newtonsoft.Json.dll
Can I use this under Linux (/HomeSeer/bin/Newtonsoft.Json.dll)?
If Newtonsoft is already include in Homeseer why do I need to edit the settings.ini file?
Does anyone have a working code for the Newtonsoft method (I've read that this method is a lot faster)?
I've ran this script
Code:
IMPORTS Newtonsoft.Json IMPORTS Newtonsoft.Json.Linq Sub Main(ByVal Parms As Object) Dim strReturn As String = "{}" Dim obj as New JObject obj = JsonConvert.DeserializeObject(strReturn) End Sub
Code:
Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: 'JObject' is not declared. It may be inaccessible due to its protection level. Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: The import 'Newtonsoft.Json.Linq' could not be found. Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: The import 'Newtonsoft.Json' could not be found. Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: The import 'System.Core' could not be
Code:
Imports System.Web.Script.Serialization Sub Main(ByVal Parms As Object) Dim json As New JavaScriptSerialize End Sub
Code:
Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: 'JavaScriptSerialize' is not declared. It may be inaccessible due to its protection level. Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: The import 'System.Web.Script.Serialization' could not be found. Error Compiling script /etc/HomeSeer/scripts/Test/test.vb: The import 'System.Core' could not be found.
Comment