私はlinqの結果を返すいくつかのコードを持っています(私も追加しようとしましたToList()
)
コレクションを見る OK
しかし、関数本体から出ると、別の抽象化レイヤーが追加されます
最後に、クライアントに結果を返すとき
それが取得します:
"{ アプリ = System.Collections.Generic.List 1[\u003c\u003ef__AnonymousType1
4[System.String,System.String,\u003c\u003ef__AnonymousType0`4[System.String,System.String,System.String,System.String],System.Object]] 、ステータス = 成功}"
linq の結果を正しくシリアル化するにはどうすればよいですか?
更新
以前は、呼び出しなしで動作していましたJSON()
public object GetAppsData()
{
var appsData = new List<AppData>();
using (IDataReader dr = DatabaseFactory.CreateDatabase().ExecuteReader("usp_AppsData_GetAll"))
{
while (dr.Read())
{
appsData.Add(new AppData()
{
AppGuid = (Guid)dr["AppGuid"],
AppName = (string)dr["AppName"],
ClientAppID = dr["ClientAppID"] == DBNull.Value ? null : (string)dr["ClientAppID"],
Url = dr["Url"] == DBNull.Value ? null : (string)dr["Url"],
DisplayName = dr["DisplayName"] == DBNull.Value ? null : (string)dr["DisplayName"],
AppDesc = dr["AppDesc"] == DBNull.Value ? null : (string)dr["AppDesc"],
PrivacyPolicyUrl = dr["PrivacyPolicyUrl"] == DBNull.Value ? null : (string)dr["PrivacyPolicyUrl"],
TermsOfUseUrl = dr["TermsOfUseUrl"] == DBNull.Value ? null : (string)dr["TermsOfUseUrl"],
//Platform = dr["Platform"] == DBNull.Value ? null : (string)dr["Platform"],
//MaxVersion = dr["MaxVersion"] == DBNull.Value ? null : (string)dr["MaxVersion"],
LocalizationKey = dr["LocalizationKey"] == DBNull.Value ? null : (string)dr["LocalizationKey"],
Compatibility = dr["Compatibility"] == DBNull.Value ? null : jss.Deserialize<object>((string)dr["Compatibility"])
});
}
}
var appsDataJson = appsData.Select(GenerateAppsDataClientResponse);
return new { apps = appsDataJson, Status = "succeeded" };
}
private object GenerateAppsDataClientResponse(AppData a)
{
object result;
if (a.Compatibility == null)
{
result = new
{
id = a.ClientAppID,
url = a.Url,
optionsDialog = new
{
displayName = a.DisplayName,
appDesc = a.AppDesc,
privacyPolicyUrl = a.PrivacyPolicyUrl,
termsOfUseUrl = a.TermsOfUseUrl
}
};
}
else
{
// this line throws NullReferenceException
result = new
{
id = a.ClientAppID,
url = a.Url,
optionsDialog = new
{
displayName = a.DisplayName,
appDesc = a.AppDesc,
privacyPolicyUrl = a.PrivacyPolicyUrl,
termsOfUseUrl = a.TermsOfUseUrl
},
compatibility = a.Compatibility
};
}
return result;
}
}
と
[HttpGet]
public ActionResult GetAppsData()
{
try
{
AppsDataManager appsData = new AppsDataManager();
object adr = appsData.GetAppsData();
return this.JsonpOptional(adr);
}
catch (Exception ex)
{
Log.Application.Error("ClientDataController.GetSettings", ex);
return this.JsonpOptional(new { Status = "failed", Reason = ex.Message });
}
}