Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#json newtonsoft转换_C#_Json - Fatal编程技术网

c#json newtonsoft转换

c#json newtonsoft转换,c#,json,C#,Json,我正在尝试从此json创建序列化字符串: report_details = { 'reportTypeLang' : 'conversations', 'reportDirections' : { 'selected' : 'inbound' }, 'times' : { 'dateRange' : 'Last5Minutes' }, 'filters' : { 'sdfDips_0' : 'in_AC10033A_AC10033A-410' }, 'dataGranularity' : { '

我正在尝试从此json创建序列化字符串:

report_details = {
'reportTypeLang' : 'conversations',
'reportDirections' : {
'selected' : 'inbound'
},
'times' : {
'dateRange' : 'Last5Minutes'
},
'filters' : {
'sdfDips_0' : 'in_AC10033A_AC10033A-410'
},
'dataGranularity' : {
'selected' : 'auto'
}
到目前为止,我已经创建了以下类:

public class ReportDetails
{
    public string reportTypeLang { get; set; }
    public ReportDirections reportDirections { get; set; }
    public Times times { get; set; }
    public Filters filters { get; set; }
    public DataGranularity dataGranularity { get; set; }
}
public class ReportDirections
{
    public string selected { get; set; }
}
public class Times
{
    public string dateRange { get; set; }
}
public class Filters
{
    public string sdfDips_0 { get; set; }
}

public class DataGranularity
{
    public string selected { get; set; }
}
并尝试使用此代码生成数据:

ReportDetails ReportDetails = new ReportDetails();
ReportDetails.reportTypeLang = "conversations";

ReportDirections reportDirections = new ReportDirections();
reportDirections.selected = "inbound";

Times Times = new Times();
Times.dateRange = "Last5Minutes";

Filters Filters = new Filters();
Filters.sdfDips_0 = "in_AC10033A_AC10033A-410";

DataGranularity DataGranularity = new DataGranularity();
DataGranularity.selected = "auto";

string report_details = JsonConvert.SerializeObject(ReportDetails);
但这似乎只会导致这个目标:

"{\"reportTypeLang\":\"conversations\",\"reportDirections\":null,\"times\":null,\"filters\":null,\"dataGranularity\":null}"

如何根据原始json对所有部分进行排列?

您没有分配其他属性。因此,它们的序列化值保持为空

只需添加它们,就像您分配了reportTypeLang:

ReportDirections reportDirections = new ReportDirections();
reportDirections.selected = "inbound";

ReportDetails ReportDetails = new ReportDetails();
ReportDetails.reportTypeLang = "conversations";
ReportDetails.reportDirections = reportDirections; // and so with the other props

另请注意:如果您不想自己写下必要的类,有一个很酷的特性“将JSON粘贴为类”,它可以自动为您生成必要的类:


您没有分配其他属性。因此,它们的序列化值保持为空

只需添加它们,就像您分配了reportTypeLang:

ReportDirections reportDirections = new ReportDirections();
reportDirections.selected = "inbound";

ReportDetails ReportDetails = new ReportDetails();
ReportDetails.reportTypeLang = "conversations";
ReportDetails.reportDirections = reportDirections; // and so with the other props

另请注意:如果您不想自己写下必要的类,有一个很酷的特性“将JSON粘贴为类”,它可以自动为您生成必要的类:


您没有分配其他属性。因此,它们的序列化值保持为空

只需添加它们,就像您分配了reportTypeLang:

ReportDirections reportDirections = new ReportDirections();
reportDirections.selected = "inbound";

ReportDetails ReportDetails = new ReportDetails();
ReportDetails.reportTypeLang = "conversations";
ReportDetails.reportDirections = reportDirections; // and so with the other props

另请注意:如果您不想自己写下必要的类,有一个很酷的特性“将JSON粘贴为类”,它可以自动为您生成必要的类:


您没有分配其他属性。因此,它们的序列化值保持为空

只需添加它们,就像您分配了reportTypeLang:

ReportDirections reportDirections = new ReportDirections();
reportDirections.selected = "inbound";

ReportDetails ReportDetails = new ReportDetails();
ReportDetails.reportTypeLang = "conversations";
ReportDetails.reportDirections = reportDirections; // and so with the other props

另请注意:如果您不想自己写下必要的类,有一个很酷的特性“将JSON粘贴为类”,它可以自动为您生成必要的类: