c# 4.0 - MDX result to JSON using C# -
i'm new mdx, need serialize ssas mdx result json object.
mdx query:
select ( [measures].[max available] ) on columns , non empty ( [application].[product].children * [application].[application name].children ) dimension properties member_caption on rows [applications] let's have mdx result looks like:
__________________________________ | | | measure1 | | product1 | feature1 | 1 | | product1 | feature2 | 1 | | product1 | feature3 | 10 | | product2 | feature1 | 1 | | product2 | feature2 | 1 | | product3 | feature1 | 1 | | product3 | feature2 | 1 | | product3 | feature3 | 1 | | product3 | feature4 | 1 | i need create json object looks (i don't need measurement values, used them valid list of products , features in mdx heirarchy):
[ { "product":"product1", "feature":[ "feature1", "feature2", "feature3" ] }, { "product":"product2", "feature":[ "feature1", "feature2" ] }, { "product":"product3", "feature":[ "feature1", "feature2", "feature3", "feature4" ] }, { ... } ] i use adomd.net library using executecellset(), i'm new 1 well. can point me right direction?
thanks, dfox
although not familiar mdx, have used json in c#. 1 way create json object (since not native in c# of 4.5) using datacontracts.
using system.runtime.serialization.json; using system.runtime.serialization; namespace interface.data { [datacontract] class jsonobject { [datamember] public string product=""; [datamember] public string[] feature={"", "", ""}; public jsonobject(){} } } then in mdx query, assuming storing query data in string 'line', can do:
using system.runtime.serialization.json; using system.data.common; using system.io; static jsonobject json; public static mdxobj parsemdxobj(string line) { mdxobj obj = new mdxobj(getmdx()); try { datacontractjsonserializer ser = new datacontractjsonserializer(typeof(jsonobject)); memorystream stream = new memorystream(asciiencoding.utf8.getbytes(line)); json = (jsonobject)ser.readobject(stream); } catch (exception e) { console.writeline("error occurred in creating json: " + e.message); return null; } return obj; }
Comments
Post a Comment