Code Bye

JSON对象转成dynamic怎么样获取属性

这有一个GeoJSON对象,本人把它转换成dynamic类型变量dy
{“type”:”GeometryCollection”,”geometries”:[
{“type”:”Point”,”coordinates”:[-342419109908.69024,146751047103.7244]},
{“type”:”Point”,”coordinates”:[-230354673938.57346,-36465411704.56182]},
{“type”:”Point”,”coordinates”:[-13341004282.156763,-57811018556.01264]},
{“type”:”Point”,”coordinates”:[111175035684.6397,73820223694.60075]},
{“type”:”Point”,”coordinates”:[89829428833.18887,258815483073.84122]},
{“type”:”Point”,”coordinates”:[-107617434542.73123,322852303628.19366]},
{“type”:”Point”,”coordinates”:[-239248676793.34463,255257881931.93274]}
]}
本人可以通过dy.type获取到geometrycollection,本人假如想获取到Point和坐标值,该怎么样操作?
解决方案

40

那谁知道,你又没告诉我们对象的结构
            var s = File.ReadAllText("d7.txt");
            var a = JObject.Parse(s);
            for (var i = 0; i < a["geometries"].Count(); i++)
            {
                Console.WriteLine("x={0} y={1}", a["geometries"][i]["coordinates"][0], a["geometries"][i]["coordinates"][1]);
            }



CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明JSON对象转成dynamic怎么样获取属性