{"id":1435,"date":"2008-10-16T23:51:00","date_gmt":"2008-10-16T14:51:00","guid":{"rendered":"https:\/\/hdmr.org\/d\/?e=156"},"modified":"2008-10-16T23:51:00","modified_gmt":"2008-10-16T14:51:00","slug":"blogn-156","status":"publish","type":"post","link":"https:\/\/hdmr.org\/d\/?e=156","title":{"rendered":"JSON\u3068\u52d5\u7684\u578b\u4ed8\u3051\u306eIronPython"},"content":{"rendered":"<p>IronPython\u306f\u52d5\u7684\u578b\u4ed8\u3051\u3092\u3084\u308b\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u5b9f\u306f\u3042\u308a\u304c\u305f\u3044\u3053\u3068\u304c\u591a\u3044\u3002<br \/>\u8fd4\u308a\u5024\u304cobject\u578b\u3060\u308d\u3046\u304c\u3001\u5b9f\u969b\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3001\u4f55\u578b\u304b\u3068\u3044\u3046\u306e\u306b\u6ce8\u76ee\u3057\u3066\u304f\u308c\u308b\u3002<br \/>\u3053\u308c\u306fC#\u3067\u306f\u8003\u3048\u3089\u308c\u306a\u3044\u3053\u3068\u3067\u3001C#\u3067\u306f\u3044\u3061\u3044\u3061\u30ad\u30e3\u30b9\u30c8\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3002<br \/>\u7d50\u69cb\u3001.NET Framework\u306f\u52d5\u7684\u578b\u4ed8\u3051\u3092\u3046\u307e\u304f\u3084\u3063\u3066\u304f\u308c\u308b\u306a\u3093\u3066\u306e\u3082IronPython\u306e\u6210\u679c\u3067\u3059\u304b\u3089\u306d\u3002<br \/>\u3053\u3046\u3044\u3046\u306e\u306f\u4fbf\u5229\u306b\u4f7f\u3063\u3066\u3044\u304d\u305f\u3044\u3082\u306e\u3060\u3002<br \/>\u305f\u3060\u30a4\u30f3\u30bf\u30d7\u30ea\u30bf\u3068\u3044\u3046\u3060\u3051\u3067\u306a\u304f\u3001\u3053\u3046\u3044\u3046\u3053\u3068\u3082\u3042\u308b\u3093\u3067\u3059\u3002<\/p>\n<hr \/>\n<p>\u5b9f\u306f\u3053\u308c<a href=\"http:\/\/james.newtonking.com\/pages\/json-net.aspx\">Json.NET<\/a>\u306e\u8a71\u306a\u3093\u3067\u3059\u3051\u3069\u306d\u3002<br \/>JSON\u306f\u975e\u5e38\u306b\u6271\u3044\u3084\u3059\u3044\u306e\u3067\u3001\u3044\u308d\u3044\u308d\u8a66\u3057\u3066\u307f\u3088\u3046\u3068\u3044\u3046\u308f\u3051\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304d\u305f\u3002<br \/>\u3068\u3053\u308d\u3067\u3001IronPython\u306a\u306e\u3060\u304c\u3001CPython\u3068\u3044\u3046\u6a19\u6e96\u306ePython\u306e2.4\u7cfb\u307e\u3067\u306e\u6a5f\u80fd\u304c\u8f09\u3063\u3066\u308b\u3089\u3057\u3044\u3002<br \/>\u3067\u3001JSON\u95a2\u4fc2\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306f2.6\u304b\u3089\u8ffd\u52a0\u3055\u308c\u305f\u3089\u3057\u304f\u3001IronPython\u3060\u304b\u3089\u3068\u3044\u3046\u306e\u306f\u306a\u304b\u3063\u305f\u3002<br \/>\u975e\u5e38\u306b\u6b8b\u5ff5\u306a\u306e\u3060\u304c\u3001C#\u3067\u306e\u52c9\u5f37\u3068\u601d\u3063\u3066\u3084\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u305f\u3002<br \/>\u305d\u308c\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u306e\u3060\u304c\u3001.NET Framework 2.0\u3067\u4f7f\u3044\u305f\u3044\u4eba\u306f1.3\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<br \/>\u3055\u3066\u3001\u3053\u306eJson.NET\u306f\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u30fb\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3092\u63d0\u4f9b\u3057\u3066\u3044\u308b\u3002<br \/>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3059\u308b\u306b\u306fNewtonsoft.Json.JavaScriptConvert.SerializeObject\u30e1\u30bd\u30c3\u30c9\u3092\u3001<br \/>\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u306f\u3001Newtonsoft.Json.JavaScriptConvert.DeserializeObject<t>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3068\u3044\u3044\u3068\u304a\u3082\u3046\u3002<br \/>Newtonsoft.Json.JavaScriptConvert.DeserializeObject\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u5358\u306b\u6587\u5b57\u5217\u3092\u51e6\u7406\u3057\u305f\u3068\u304d\u3069\u3046\u306a\u308b\u304b\u898b\u3066\u305f\u3002<br \/>\u3059\u308b\u3068\u3001\u6570\u5b57\u306f\u6574\u6570\u306fInt64(long)\u3001\u5c0f\u6570\u306fdouble\u3001\u6587\u5b57\u5217\u306fstring\u3068\u304b\u3002<br \/>JavaScript\u306e\u914d\u5217\u306fNewtonsoft.Json.JavaScriptObjectArray\u578b\u3001Object\u306fNewtonsoft.Json.JavaScriptObject\u578b\u307f\u305f\u3044\u3002<br \/>\u3067\u3001\u5b9f\u306f\u305d\u308c\u305e\u308c\u3001System.Collections.Generic.List&lt;object>\u3001System.Collections.Generic.Dictionary<string,object>\u3092\u7d99\u627f\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\u307e\u3041\u306a\u3093\u3067\u3001\u3042\u307e\u308a\u6c17\u306b\u305b\u305a[]\u3067\u56f2\u307e\u308c\u3066\u308b\u306e\u306fList&lt;object>\u3001{}\u3067\u56f2\u307e\u308c\u3066\u308b\u306e\u306fDictionary<string,object>\u3060\u3068\u3002<\/p>\n<pre># encoding:utf-8<br \/>import clr<br \/>import System<br \/>clr.AddReferenceToFile(\"Newtonsoft.Json.dll\")<br \/>import Newtonsoft.Json<br \/>def main():<br \/>  res=Newtonsoft.Json.JavaScriptConvert.DeserializeObject(\"[1,[2,3,4]]\")<br \/>  print res[0]<br \/>  for cur in res[1]:<br \/>    print \">%d\"%(cur,)<br \/>  res=Newtonsoft.Json.JavaScriptConvert.DeserializeObject('{\"foo\":\"bar\",\"hoge\":100,\"hage\":20}')<br \/>  print res['hoge']*res['hage']<br \/>  for cur in res:<br \/>    print \"%-5s: %s\"%(cur.Key,cur.Value)<br \/>if __name__=='__main__':<br \/>  main()<\/pre>\n<p>\u307e\u3041\u3001\u3053\u3093\u306a\u611f\u3058\u3002C#\u3067\u66f8\u304f\u3068\u3053\u3046\u30b7\u30f3\u30d7\u30eb\u306b\u306f\u884c\u304b\u306a\u3044\u3002<br \/>\u305d\u308c\u3067\u6ce8\u610f\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u306f\u3001Dictionary<string,object>\u3092for\u3067\u56de\u3059\u3068\u304d\u3001<\/p>\n<pre>  for key,val in res.iteritems():<br \/>    print \"%-5s: %s\"%(key,val)<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306a\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002<br \/>\u307e\u3041\u3042\u304f\u307e\u3067\u3082Python\u306e\u8f9e\u66f8\u578b\u3068.NET Framework\u306eDictionary\u30af\u30e9\u30b9\u306f\u9055\u3046\u3068\u8a00\u3046\u3053\u3068\u3067\u3059\u3002<br \/>Dictionary\u30af\u30e9\u30b9\u306fKeyValuePair\u30921\u3064\u3065\u3064\u53d6\u308a\u51fa\u3057\u3066\u56de\u3059\u3082\u306e\u306a\u306e\u3067\u3001\u305d\u306e\u8fba\u6ce8\u610f\u3002<\/p>\n<hr \/>\n<p>\u9006\u306b\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3059\u308b\u3068\u304d\u3060\u3051\u3069\u3001\u307e\u3041\u3053\u3061\u3089\u306f\u305d\u3093\u306a\u306b\u6c17\u306b\u3057\u306a\u304f\u3066\u3044\u3044\u3088\u3046\u306a\u3002<\/p>\n<pre>def main():<br \/>  print Newtonsoft.Json.JavaScriptConvert.SerializeObject( [1,2,3] )<br \/>  print Newtonsoft.Json.JavaScriptConvert.SerializeObject( (4,5,6) )<br \/>  obj=System.Collections.Generic.Dictionary[str,object]( {'John':100,'Tom':200} )<br \/>  print Newtonsoft.Json.JavaScriptConvert.SerializeObject( obj )<\/pre>\n<p>\u307e\u3041\u898b\u308a\u3083\u308f\u304b\u308b\u306d\u3001\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u304c\u3002<br \/>\u305f\u3060\u3053\u308c\u3082\u3001Python\u306e\u8f9e\u66f8\u578b\u3058\u3083\u306a\u304f\u3066\u3001.NET\u306eDictionary\u30af\u30e9\u30b9\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308b\u3002<br \/>\u4e00\u65b9\u3001Python\u306e\u30ea\u30b9\u30c8\u30fb\u30bf\u30d7\u30eb\u306f\u305d\u306e\u307e\u307e\u4f7f\u3048\u308b\u3002<br \/>\u3069\u3046\u3082\u3053\u3063\u3061\u306fIEnumerable\u306a\u3089OK\u307f\u305f\u3044\u3067\u3059\u3002<\/p>\n<hr \/>\n<p>IronPython\u3067\u3044\u308d\u3044\u308d\u3084\u3063\u3066\u304d\u307e\u3057\u305f\u304c\u3001<br \/>C#\u3067\u306f\u578b\u306e\u52a0\u6e1b\u304c\u3042\u308b\u306e\u3067\u3001List&lt;object>\u3001Dictionary<string,object>\u3067\u3044\u3058\u308b\u306e\u3067\u306f\u306a\u304f\u3001<br \/>\u81ea\u4f5c\u30af\u30e9\u30b9\u3092\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u30fb\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3059\u308b\u306e\u304c\u3088\u3055\u305d\u3046\u3002<\/p>\n<pre>      vector v=new vector(2,3);<br \/>      string json=Newtonsoft.Json.JavaScriptConvert.SerializeObject(v);<br \/>      Console.WriteLine(json);<br \/>      v=Newtonsoft.Json.JavaScriptConvert.DeserializeObject<vector>(\"{\\\"x\\\":10,\\\"y\\\":20}\");<br \/>      Console.WriteLine(v);<\/pre>\n<p>\u307e\u3041\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<br \/>JSON\u306f\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3059\u3068\u3044\u3046\u3088\u308a\u304b\u306f\u3001\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u3067\u9001\u308b\u306e\u304c\u304a\u304a\u3044\u304b\u306a\u3068\u3002<br \/>XML\u306e\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3082\u6a19\u6e96\u3067\u4f7f\u3048\u307e\u3059\u3057\u306d\u3002<br \/>\u307e\u3041\u305d\u306e\u8fba\u306f\u597d\u304d\u306b\u3069\u3046\u305e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>IronPython\u306f\u52d5\u7684\u578b\u4ed8\u3051\u3092\u3084\u308b\u306e\u3060\u304c\u3001\u3053\u308c\u306f\u5b9f\u306f\u3042\u308a\u304c\u305f\u3044\u3053\u3068\u304c\u591a\u3044\u3002\u8fd4\u308a\u5024\u304cobject\u578b\u3060\u308d\u3046\u304c\u3001\u5b9f\u969b\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3001\u4f55\u578b\u304b\u3068\u3044\u3046\u306e\u306b\u6ce8\u76ee\u3057\u3066\u304f\u308c\u308b\u3002\u3053\u308c\u306fC#\u3067\u306f\u8003\u3048\u3089\u308c\u306a\u3044\u3053\u3068\u3067\u3001C#\u3067\u306f\u3044\u3061\u3044\u3061\u30ad\u30e3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1435","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1435"}],"version-history":[{"count":0,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1435\/revisions"}],"wp:attachment":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}