-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlfile_JSON.cs
More file actions
53 lines (45 loc) · 1.51 KB
/
htmlfile_JSON.cs
File metadata and controls
53 lines (45 loc) · 1.51 KB
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
44
45
46
47
48
49
50
51
52
// Example: Parsing JSON in C# using Internet Explorer COM object
// Requires Internet Explorer 9+
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static Dictionary<string,object> GetObjectProperties(object o)
{
var res = new Dictionary<string, object>();
foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(o))
{
res.Add(prop.Name,prop.GetValue(o));
}
return res;
}
[STAThread]
static void Main(string[] args)
{
dynamic html = Activator.CreateInstance(Type.GetTypeFromProgID("htmlfile"));
try
{
html.open();
html.write("<html><head><meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" /></head><body></body></html>");
dynamic JSON = html.defaultView.JSON;
dynamic obj = JSON.parse(
"{\"a\":true, \"b\":10, \"c\": \"Hello\"}"
);
var dict = GetObjectProperties(obj);
foreach (string prop in dict.Keys)
{
Console.WriteLine(prop + ": " + dict[prop].ToString());
}
}
finally
{
html.close();
}
Console.ReadKey();
}
}
}