小编dye*_*yes的帖子

自定义反序列化器仅适用于json.NET的某些字段

我正在尝试反序列化一些JSON:

{ 
   "a":1,
   "b":25,
   "c":"1-7",
   "obj1":{ 
      "a1":10,
      "b1":45,
      "c1":60
   },
   "obj2":[ 
      { 
         "a2":100,
         "b2":15,
         "c2":50
      },
      { 
         "e2":"1,2,5-7",
         "f2":"1,3-5",
         "a2":25
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我想找到一种方法来定义仅针对某些字段的自定义反序列化.

在下面的代码中,我将需要注意的字段(自定义处理)和可以以某种方式自动完成的字段分开.

是否可以自动反序列化"正常"字段?(不需要任何特定的自定义处理)

[JsonConverter(typeof(ConfigurationSerializer))]
    public class Configuration
    {
        public int a { get; set; }
        public int b { get; set; }
        public Obj1 obj1 { get; set; }

        public int[] c { get; set; }
        public IList<Obj2> obj2 { get; set; }
    }

    public class ConfigurationSerializer : JsonConverter
    {
        public override void WriteJson(JsonWriter writer, object value, …
Run Code Online (Sandbox Code Playgroud)

c# json.net json-deserialization

9
推荐指数
1
解决办法
5749
查看次数

成功发布dotnet后缺少软件包

publish命令工作正常,但是运行后,由于缺少软件包,我必须还原项目...

因此,如果我运行以下命令:

dotnet发布--runtime win-x64

然后进行发布,但是之后我的项目中缺少程序包。

但是如果我没有运行就运行发布:

dotnet发布

然后发布工作正常,我没有任何缺少的程序包。

这是正常行为吗?我该怎么做才能解决此问题?真烦人

这是我的csproj文件:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="AWSSDK.Extensions.NETCore.Setup">
        <Version>3.3.6</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.App">
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles">
        <Version>2.1.1</Version>
    </PackageReference>
    <PackageReference Include="NSwag.AspNetCore">
        <Version>12.0.13</Version>
    </PackageReference>
    <PackageReference Include="NSwag.MSBuild">
        <Version>12.0.13</Version>
    </PackageReference>
</ItemGroup>
<ItemGroup>
    <ProjectReference Include="..\MyProject.Analytics\MyProject.Analytics.csproj" />
    <ProjectReference Include="..\MyProject.ApiClient\MyProject.ApiClient.csproj" />
    <ProjectReference Include="..\MyProject.CommonApi\MyProject.CommonApi.csproj" />
    <ProjectReference Include="..\MyProject.Common\MyProject.Common.csproj" />
    <ProjectReference Include="..\MyProject.DbAccess\MyProject.DbAccess.csproj" />
    <ProjectReference Include="..\MyProject.Logging\MyProject.Logging.csproj" />
    <ProjectReference Include="..\MyProject.Messaging\MyProject.Messaging.csproj" />
    <ProjectReference Include="..\MyProject.Model\MyProject.Model.csproj" />
    <ProjectReference Include="..\MyProject.Settings\MyProject.Settings.csproj" />
</ItemGroup>
<ItemGroup>
    <Content Update="appsettings.Api.Development.json">
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Update="appsettings.Api.json">
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Update="appsettings.Api.Production.json"> …
Run Code Online (Sandbox Code Playgroud)

publish nuget asp.net-core

6
推荐指数
1
解决办法
149
查看次数

"AS"等同于sqlite

我是来自mysql的sqlite的初学者.也许我的问题是愚蠢的,但我无法在mysql中找到相当于"AS"的例子.

例: "SELECT firstName || ' ' || lastName AS fullName FROM myTable;"

可能吗?

提前致谢!

java sqlite android

4
推荐指数
1
解决办法
7724
查看次数

Stackoverflow:递归调用太多了?在C.

我正在尝试通过一个巨大的图形(大约875000个节点和5200000个边缘),但我得到了一个stackoverflow.我有一个递归函数来循环它.它将仅探索未探索的节点,因此无法进入无限递归.(或者至少我认为)我的递归函数适用于较小的输入(5000个节点).

我该怎么办?是否有最大数量的成功递归调用?

我真的很无能为力.

编辑:我也在最后发布了迭代等价物.

这是递归的代码:

int main()
{
int *sizeGraph,i,**reverseGraph;
// some code to initialize the arrays
getGgraph(1,reverseGraph,sizeGraph); // populate the arrays with the input from a file

getMagicalPath(magicalPath,reverseGraph,sizeGraph);

return 0;
}

void getMagicalPath(int *magicalPath,int **graph,int *sizeGraph) {
    int i;
    int *exploredNode;
    /* ------------- creation of the list of the explored nodes ------------------ */
    if ((exploredNode =(int*) malloc((ARRAY_SIZE + 1) * sizeof(exploredNode[0]))) == NULL) {
        printf("malloc of exploredNode error\n");
        return;
    }
    memset(exploredNode, 0, (ARRAY_SIZE + 1) * sizeof(exploredNode[0]));

    // start …
Run Code Online (Sandbox Code Playgroud)

c stack-overflow recursion graph

4
推荐指数
2
解决办法
3546
查看次数

在Qt中用C++动态添加未知数量的按钮到UI

我试图在网格布局中插入QPushButton非常简单,但我不会提前知道这个数字.

这是我有的:

testapp.cpp

#include "testapp.h"

testApp::testApp(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            QPushButton* panelButton = new QPushButton();
            panelButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
            ui.PanelButtonGridLayout->addWidget(panelButton,i,j);
        }
    }
}

testApp::~testApp()
{

}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include <QtGui/QApplication>

#include "testapp.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    testApp w;
    w.show();
    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

所以我知道这不会起作用,因为在当前循环结束时将删除该对象.

我考虑在main中创建QPushButton的QList(例如)并将其传递给testapp类,但我不确定它是一个很好的解决方案.可能有更好的方法.

编辑:由于某些原因,它没有编译.现在是.我讨厌那个到来的时候.

c++ user-interface qt

4
推荐指数
1
解决办法
4306
查看次数

使用QThread和QTcpSocket正确使用QThread和moveToThread

从阅读这篇博客,这个博客和其他一些人,Subclassing QThread是不好的做法.所以我尝试应用这种方法.

但我的问题是我在类中有一个QTimer和一个QTcpSocket我想转移到另一个线程.突然间,它并不像使用的例子那么容易.:(

QThread m_commsThread;
m_pICommsHandler = new CommsHandlerIP();
m_pICommsHandler->moveToThread(&m_commsThread);
m_commsThread.start();
Run Code Online (Sandbox Code Playgroud)

这里是CommsHandlerIP类,不包括方法.

class CommsHandlerIP : public QObject
{
    Q_OBJECT
public:
    CommsHandlerIP();
    ~CommsHandlerIP(void);
protected:
    QTcpSocket m_TCPSocket;
    QTimer m_timer;
}
Run Code Online (Sandbox Code Playgroud)

问题是即使你移动CommsHandlerIP,QTimer和QTcpSocket(在CommsHandlerIP类内)也在主线程中.所以我无法启动计时器或连接插座.

如果我尝试moveToThread QTimer和QTcpSocket(在构造函数中通过传递线程指针),当我离开应用程序时,这变得非常混乱.

我该怎么办?

c++ qt multithreading qthread

4
推荐指数
1
解决办法
6719
查看次数

如何与Jackson一起全局定义命名约定

我在Spring上使用Jackson。我有几种这样的方法:

@RequestMapping(value = "/myURL", method = RequestMethod.GET)
public @ResponseBody Foo getFoo()  {
    // get foo
    return foo;
}
Run Code Online (Sandbox Code Playgroud)

序列化的Foo类很大,并且有很多成员。使用注释或自定义序列化程序可以进行序列化。

我唯一不知道的是如何定义命名约定。我想对所有序列化使用snake_case。

那么,如何为全局定义序列化的命名约定?

如果不可能的话,则必须采用本地解决方案。

java spring jackson spring-boot

4
推荐指数
2
解决办法
4920
查看次数

使用带有JSF的get http变量和良好实践

1)在JSF中使用get http变量是一个好习惯吗?似乎它试图避免这种情况.

2)这是我想要做的:在第一页上,我有一个链接列表,如果你点击链接,你有一个页面与其他链接等像树.我希望用户能够访问第三深度(例如)而无需从顶层开始(例如,通过带有get变量中相关对象ID的链接).

所以我的问题是:如何从托管bean设置get http变量?

为了得到它,这篇文章很清楚:获取http变量JSF

3)当然,如果您有其他解决方案,请随时分享.

jsf

3
推荐指数
1
解决办法
763
查看次数

ClassName变量(arg1)之间的区别; 和ClassName变量= ClassName(arg1);

你如何称呼这两种不同的方式,它们有何不同?

ClassName variable(arg1); 
Run Code Online (Sandbox Code Playgroud)

ClassName variable = ClassName(arg1);
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
51
查看次数