This project is read-only.

SmartObject

SmartObject is a DynamicObject for .NET

Features

  • Flexible JSON serializer for converting between SmartObject and JSON
  • easy to get and set SmartObject's porperties

Use Guide

Add Reference Spider.Common.dll
System.Web.Extensions.dll

// HowToUse
using Spider.Data;
    //json example from http://www.json.org/example.html
    string json1 = @"{""widget"": {
    ""debug"": ""on"",
    ""window"": {
        ""title"": ""Sample Konfabulator Widget"",
        ""name"": ""main_window"",
        ""width"": 500,
        ""height"": 500
    },
    ""image"": { 
        ""src"": ""Images/Sun.png"",
        ""name"": ""sun1"",
        ""hOffset"": 250,
        ""vOffset"": 250,
        ""alignment"": ""center""
    },
    ""text"": {
        ""data"": ""Click Here"",
        ""size"": 36.23,
        ""style"": ""bold"",
        ""name"": ""text1"",
        ""hOffset"": 250,
        ""vOffset"": 100,
        ""alignment"": ""center"",
        ""onMouseUp"": ""sun1.opacity = (sun1.opacity / 100) * 90;""
    }
} } ";
            string json2 = @"{""menu"": {
  ""id"": ""file"",
  ""value"": ""File"",
  ""popup"": {
    ""menuitem"": [
      {""value"": ""New"", ""onclick"": 2},
      {""value"": ""Open"", ""onclick"": 1.2},
      {""value"": ""Close"", ""onclick"": 55555}
    ]
  }
} }";
            dynamic o1 = SmartObject.Parse(json1);
            dynamic o2 = SmartObject.Parse(json2);
            Console.WriteLine(o1.widget.text.size);
            Console.WriteLine(o1.widget.text[1]);
            Console.WriteLine(o1.widget.text["size"]);
            Console.WriteLine(o1.ToJson());// ToJson return json string
            Console.WriteLine(o2.ToJson());
            dynamic o3=new SmartObject();
            o3.A="abc";
            o3["B"]=2345;
            Console.WriteLine(o3.IsDefine("C"));
            IDictionary<string, object> dict=o3.AsDictionary();


The details documentation adress is: https://smartobject.codeplex.com/documentation
kingge168@gmail.com

Last edited Jan 3, 2014 at 6:16 AM by kingge168, version 5