gpt4 book ai didi

json - 在SenseNet设置中使用JSON数组

转载 作者:行者123 更新时间:2023-12-03 01:22:35 24 4
gpt4 key购买 nike

如果在SenseNet设置对象中使用JSON数组,则无法通过OData API访问它们。

例如,考虑以下 SenseNet 设置对象,默认安装在 Root/System/Settings/Portal.settings:

{
ClientCacheHeaders: [
{ ContentType: "PreviewImage", MaxAge: 1 },
{ Extension: "jpeg", MaxAge: 604800 },
{ Extension: "gif", MaxAge: 604800 },
{ Extension: "jpg", MaxAge: 604800 },
{ Extension: "png", MaxAge: 604800 },
{ Extension: "swf", MaxAge: 604800 },
{ Extension: "css", MaxAge: 600 },
{ Extension: "js", MaxAge: 600 }
],
UploadFileExtensions: {
"jpg": "Image",
"jpeg": "Image",
"gif": "Image",
"png": "Image",
"bmp": "Image",
"svg": "Image",
"svgz": "Image",
"tif": "Image",
"tiff": "Image",
"xaml": "WorkflowDefinition",
"DefaultContentType": "File"
},
BinaryHandlerClientCacheMaxAge: 600,
PermittedAppsWithoutOpenPermission: "Details"
}

通过 OData API 查看此对象时,不包含 ClientCacheHeaders 字段:

{
"d": {
"UploadFileExtensions.jpg": "Image",
"UploadFileExtensions.jpeg": "Image",
"UploadFileExtensions.gif": "Image",
"UploadFileExtensions.png": "Image",
"UploadFileExtensions.bmp": "Image",
"UploadFileExtensions.svg": "Image",
"UploadFileExtensions.svgz": "Image",
"UploadFileExtensions.tif": "Image",
"UploadFileExtensions.tiff": "Image",
"UploadFileExtensions.xaml": "WorkflowDefinition",
"UploadFileExtensions.DefaultContentType": "File",
"BinaryHandlerClientCacheMaxAge": 600,
"PermittedAppsWithoutOpenPermission": "Details",
}
}

如果您使用以下查询专门搜索 ClientCacheHeaders 字段:

Odata.svc/Root/System/Settings('Portal.settings')?&metadata=no&$select=ClientCacheHeaders

API 返回 null:

{
"d": {
"ClientCacheHeaders": null
}
}

我知道设置文件中允许使用 JSON 数组,因为 SenseNet wiki page 中引用了上面的示例。描述设置用法。

我是否错误地执行了 OData 查询,或者这是 SenseNet API 中的某种解析错误?

最佳答案

这是 Miklos 建议的自定义 OData 函数的实现。完成此操作后,您必须按照描述注册 OData 调用 here .

public static class OData
{
[ODataFunction]
public static string GetMySettings(Content content)
{
var retstr = "";
try
{
var settingsFile = Settings.GetSettingsByName<Settings>("MySettings", content.Path);
var node = Node.LoadNode(settingsFile.Path) as Settings;
var bindata = node.GetBinary("Binary");

using (var sr = bindata.GetStream())
using (var tr = new System.IO.StreamReader(sr))
retstr = tr.ReadToEnd();
}
catch (Exception e)
{
SnLog.WriteException(e);
}

return retstr;
}
}

关于json - 在SenseNet设置中使用JSON数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46060152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com