c# - Reorder objects in a class -
i doing json parsing , have following results;
{ "alias": { "outlet_name": "outlet_name" }, "displayfieldname": "outlet_name", "feature": { "features": [ { "attribute": { "outlet_name": "cck 24-hr family clinic" }, "geometry": { "x": 17961.38, "y": 40715.6875 } }, { "attribute": { "outlet_name": "central clinic , surgery (bedok)" }, "geometry": { "x": 39091.43, "y": 34142.043 } }, { "attribute": { "outlet_name": "central clinic , surgery (hougang)" }, "geometry": { "x": 33835.53, "y": 39431.01 } }, { "attribute": { "outlet_name": "central clinic , surgery (yishun)" }, "geometry": { "x": 27410.125, "y": 45743.45 } }, { "attribute": { "outlet_name": "lifelink 24hrs clinic , surgery" }, "geometry": { "x": 32343.502, "y": 39151.2266 } }, { "attribute": { "outlet_name": "medihealth bishan 24 hours clinic , surgery" }, "geometry": { "x": 29984.7734, "y": 36586.86 } }, { "attribute": { "outlet_name": "mediline wei min clinic" }, "geometry": { "x": 36201.6328, "y": 31674.46 } }, { "attribute": { "outlet_name": "novena clinic 24 hours" }, "geometry": { "x": 29197.53, "y": 33659.6055 } }, { "attribute": { "outlet_name": "raffles medical airport 24-hr clinic" }, "geometry": { "x": 44899.6836, "y": 37431.73 } }, { "attribute": { "outlet_name": "silver cross family clinic (serangoon)" }, "geometry": { "x": 32329.1758, "y": 37284.06 } }, { "attribute": { "outlet_name": "shenton family medical clinic (bukit gombak)" }, "geometry": { "x": 18838.0039, "y": 37873.7656 } }, { "attribute": { "outlet_name": "medihealth bishan 24 hours clinic , surgery" }, "geometry": { "x": 39090.3164, "y": 34147.3477 } }, { "attribute": { "outlet_name": "ang mo kio polyclinic (nhg)" }, "geometry": { "x": 29549.7285, "y": 39377.99 } }, { "attribute": { "outlet_name": "bedok polyclinic (singhealth)" }, "geometry": { "x": 38940.74, "y": 34247.7461 } }, { "attribute": { "outlet_name": "bukit batok polyclinic (nhg)" }, "geometry": { "x": 18479.2949, "y": 37117.1133 } }, { "attribute": { "outlet_name": "choa chu kang polyclinic (nhg)" }, "geometry": { "x": 18832.752, "y": 40480.02 } }, { "attribute": { "outlet_name": "clementi polyclinic (nhg)" }, "geometry": { "x": 20473.0254, "y": 32777.65 } }, { "attribute": { "outlet_name": "geylang polyclinic (singhealth)" }, "geometry": { "x": 33995.8047, "y": 33537.26 } }, { "attribute": { "outlet_name": "hougang polyclinic (nhg)" }, "geometry": { "x": 34198.1172, "y": 39108.6953 } }, { "attribute": { "outlet_name": "jurong polyclinic (nhg)" }, "geometry": { "x": 16596.166, "y": 36874.918 } }, { "attribute": { "outlet_name": "marine parade polyclinic (singhealth)" }, "geometry": { "x": 36304.0234, "y": 31631.8926 } }, { "attribute": { "outlet_name": "marine parade polyclinic (singhealth)" }, "geometry": { "x": 28576.2051, "y": 29132.0039 } }, { "attribute": { "outlet_name": "tampines polyclinic (singhealth)" }, "geometry": { "x": 40523.01, "y": 37716.5547 } }, { "attribute": { "outlet_name": "toa payoh polyclinic (nhg)" }, "geometry": { "x": 30854.1777, "y": 35203.2422 } }, { "attribute": { "outlet_name": "woodlands polyclinic (nhg)" }, "geometry": { "x": 21546.4063, "y": 45844.5977 } }, { "attribute": { "outlet_name": "yishun polyclinic (nhg)" }, "geometry": { "x": 28427.4941, "y": 45016.31 } }, { "attribute": { "outlet_name": "pasir ris polyclinic (singhealth)" }, "geometry": { "x": 42028.0156, "y": 38950.3164 } }, { "attribute": { "outlet_name": "queenstown polyclinic (singhealth)" }, "geometry": { "x": 24412.3555, "y": 31231.8438 } }, { "attribute": { "outlet_name": "sengkang polyclinic (singhealth)" }, "geometry": { "x": 34765.73, "y": 41634.793 } } ] }, "field": { "fi": [ { "alias": "outlet_name", "length": 200, "name": "outlet_name", "type": "esrifieldtypestring" } ] }, "geometrytype": "esrigeometrypoint", "wkids": { "wkid": 3414 }
}
what have achieve following json format:
{ "displayfieldname": "outlet_name", "fieldaliases": { "outlet_name": "outlet_name" }, "geometrytype": "esrigeometrypoint", "spatialreference": { "wkid": 3414 }, "fields": [ { "name": "outlet_name", "type": "esrifieldtypestring", "alias": "outlet_name", "length": 200 } ], "features": [ { "attributes": { "outlet_name": "alexandra hospital" }, "geometry": { "x": 24412.561499999836, "y": 29892.22849999927 } }, { "attributes": { "outlet_name": "changi general hospital" }, "geometry": { "x": 40924.62980000023, "y": 35863.99689999968 } }, { "attributes": { "outlet_name": "national university hospital" }, "geometry": { "x": 22393.636400000192, "y": 30731.8563000001 } }, { "attributes": { "outlet_name": "singapore general hospital" }, "geometry": { "x": 28262.58440000005, "y": 29180.98860000074 } }, { "attributes": { "outlet_name": "tan tock seng hospital" }, "geometry": { "x": 29668.50810000021, "y": 33693.00019999966 } }, { "attributes": { "outlet_name": "kk women's , children's hospital" }, "geometry": { "x": 29509.814699999988, "y": 32540.03519999981 } }, { "attributes": { "outlet_name": "adam road hospital" }, "geometry": { "x": 25778.033800000325, "y": 34343.84779999964 } }, { "attributes": { "outlet_name": "mount alvernia hospital" }, "geometry": { "x": 28502.294900000095, "y": 35975.92449999973 } }, { "attributes": { "outlet_name": "paragon medical centre" }, "geometry": { "x": 28230.75270000007, "y": 31911.52370000072 } }, { "attributes": { "outlet_name": "raffles hospital" }, "geometry": { "x": 30665.577200000174, "y": 31499.313200000674 } }, { "attributes": { "outlet_name": "thomson medical centre" }, "geometry": { "x": 28906.391900000162, "y": 34174.550200000405 } }, { "attributes": { "outlet_name": "mount elizabeth hospital" }, "geometry": { "x": 28227.747800000012, "y": 31941.378900000826 } } ] }
this method in wcf service return json.
[operationcontract] [webinvoke(method = "get", responseformat = webmessageformat.json, bodystyle = webmessagebodystyle.bare, uritemplate = "json")] container getclinicinfo(); [datacontract] public class container { [datamember] public string displayfieldname { get; set; } [datamember] public fieldaliases alias { get; set; } [datamember] public string geometrytype { get; set; } [datamember] public spatialreference wkids { get; set; } [datamember] public fieldcontainer field { get; set; } [datamember] public features feature { get; set; } [datacontract] public class container { [datamember] public string displayfieldname { get; set; } [datamember] public fieldaliases alias { get; set; } [datamember] public string geometrytype { get; set; } [datamember] public spatialreference wkids { get; set; } [datamember] public fieldcontainer field { get; set; } [datamember] public features feature { get; set; } public container(string display,fieldaliases aliases,string type,spatialreference spatial,fieldcontainer container, features fea) { displayfieldname = display; alias = aliases; geometrytype = type; wkids = spatial; field = container; feature = fea; }
right now, json parsing "container" alphabetically;
image attached: http://img600.imageshack.us/img600/2861/ehaehaehaeh.png)
does have ideas how should this?
you can use order
property of [datamember]
attribute define order fields serialized:
[datacontract] public class container { [datamember(order = 1)] public string displayfieldname { get; set; } [datamember(order = 2)] public fieldaliases fieldaliases { get; set; } [datamember(order = 3)] public string geometrytype { get; set; } [datamember(order = 4)] public spatialreference spatialreference { get; set; } [datamember(order = 5)] public fieldcontainer fields { get; set; } [datamember(order = 6)] public features features { get; set; } }
Comments
Post a Comment