-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFromJsonComponent.cs
43 lines (32 loc) · 1.22 KB
/
FromJsonComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Drawing;
using Grasshopper.Kernel;
using Newtonsoft.Json.Linq;
namespace ru.Mathrioshka.ghJSON
{
public class FromJsonComponent : GH_Component
{
public FromJsonComponent():base("From JSON", "FrmJSON", "Parse JSON string", "Extra", "JSON"){}
public override Guid ComponentGuid
{
get { return new Guid("475E86C2-41FA-4F8E-9C7C-07E1E0AE06A9"); }
}
protected override Bitmap Icon { get { return Icons.FromJson; } }
protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddTextParameter("JSON", "J", "JSON string", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("JObject", "JO", "JSON Object", GH_ParamAccess.item);
}
protected override void SolveInstance(IGH_DataAccess da)
{
string jsonString = null;
if (!da.GetData(0, ref jsonString)) { return; }
if(String.IsNullOrEmpty(jsonString)) return;
var jsonObject = JObject.Parse(jsonString);
da.SetData(0, jsonObject);
}
}
}