2

私は MDX を初めて使用します。基本的に、SSAS MDX の結果を JSON オブジェクトにシリアル化する必要があります。

MDX クエリ:

SELECT
(
    [Measures].[Max Available]
) ON COLUMNS
, NON EMPTY 
(
    [Application].[Product].Children * [Application].[Application Name].Children
) DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM [Applications]

次のような MDX 結果があるとします。

__________________________________
|          |          | 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        |

次のような JSON オブジェクトを作成する必要があります (測定値は必要ありません。MDX 階層内の製品と機能の有効なリストを取得するために使用しただけです)。

[
 {
   "product":"Product1",
   "feature":[
      "Feature1",
      "Feature2",
      "Feature3"
   ]
 }, {
   "product":"Product2",
   "feature":[
      "Feature1",
      "Feature2"
   ]
 }, {
   "product":"Product3",
   "feature":[
      "Feature1",
      "Feature2",
      "Feature3",
      "Feature4"
   ]
 }, {
   ...
 }
]

私は ExecuteCellSet() を使用して ADOMD.NET ライブラリを使用していますが、これも初めてです。誰かが私を正しい方向に向けることができますか?

ありがとう、dfox

4

1 に答える 1

0

私は MDX に詳しくありませんが、C# で JSON を使用したことがあります。JSON オブジェクトを作成する 1 つの方法 (4.5 の時点で C# ではネイティブではないため) は、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(){}
    }
}

次に、MDX クエリで、クエリ データを文字列 'line' に格納すると仮定すると、次のことができます。

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;
}
于 2014-03-11T00:35:23.620 に答える