c # json newtonsoft 변환

드웨인 디 블리

이 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에 따라 모든 섹션을 어떻게 채웁니까?

khlr

다른 속성을 할당하지 않았습니다. 따라서 직렬화 된 값은 null로 유지됩니다.

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을 클래스로 붙여 넣는 멋진 기능이 있어 필요한 클래스를 직접 작성하고 싶지 않은 경우 자동 생성됩니다.

여기에 이미지 설명 입력

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Newtonsoft.Json.JsonConvert.DeserializeObject를 Newtonsoft.Json.Linq.JObject 문제로 변환

분류에서Dev

C # newtonsoft json.net을 사용하여 json 배열을 객체 목록으로 변환

분류에서Dev

Newtonsoft.Json의 JSON C # DeserializeObject 오류

분류에서Dev

Json.NET (Newtonsoft)을 사용하여 빈 배열을 JSON에서 XML로 변환

분류에서Dev

Newtonsoft Json Convert는 json 문자열을 객체로 변환하지 않습니다.

분류에서Dev

객체에 대한 C # Newtonsoft JSON

분류에서Dev

문자열을 유형으로 변환하는 중 오류-Newtonsoft JSON deserialize

분류에서Dev

Newtonsoft.Json.JsonReaderException

분류에서Dev

JSON 응답을 통해 반복 Newtonsoft.Json.Linq.JObject C #

분류에서Dev

자바의 "org.json"대 C #의 "Newtonsoft.Json.JsonConvert"

분류에서Dev

Newtonsoft를 사용하여 json 문자열을 json 배열로 변환하려면 어떻게해야합니까?

분류에서Dev

Json Newtonsoft Jarray 빌드

분류에서Dev

How to DeserializeObject with Newtonsoft.Json?

분류에서Dev

Newtonsoft 사용자 정의 Json 변환기 문자열 배열을 쉼표로 구분 된 문자열 WebApi 2

분류에서Dev

.net Core 3.1 Newtonsoft.Json은 dictionary <int, string> 키를 문자열로 변환합니다.

분류에서Dev

암시 적으로 'Newtonsoft.Json.Linq.JObject'형식을 'System.Collections.Generic.IEnumerable <Employee>'로 변환 할 수 없습니다.

분류에서Dev

NewtonSoft.Json이 모두 null을 반환합니다.

분류에서Dev

C # MVC 컨트롤 Newtonsoft.json 직렬화

분류에서Dev

NewtonSoft를 사용한 C # Chart.js 및 JSON

분류에서Dev

C # Newtonsoft JSON 맵 속성을 배열 하위 항목으로

분류에서Dev

JSON을 C # 복합 개체로 변환

분류에서Dev

Newtonsoft 변경 JSON 케이스 비활성화

분류에서Dev

C #에서 Newtonsoft Json.NET을 사용하여 JSON 역 직렬화

분류에서Dev

Newtonsoft.JSON을 사용하여 C #으로 Json 문자열 역 직렬화

분류에서Dev

JSON을 변경하지 않고 JSON 배열의 NewtonSoft Inheretance 역 직렬화

분류에서Dev

JSON 날짜를 C # datetime 변수로 변환

분류에서Dev

C # Newtonsoft.Json 최상위 수준 만 역 직렬화 하시겠습니까?

분류에서Dev

newtonsoft를 사용하여 VB.NET/C#에서 Json 파일로드

분류에서Dev

C # Newtonsoft.json DefaultContractResolver IValueProvider를 사용하여 데이터 충돌 대체

Related 관련 기사

  1. 1

    Newtonsoft.Json.JsonConvert.DeserializeObject를 Newtonsoft.Json.Linq.JObject 문제로 변환

  2. 2

    C # newtonsoft json.net을 사용하여 json 배열을 객체 목록으로 변환

  3. 3

    Newtonsoft.Json의 JSON C # DeserializeObject 오류

  4. 4

    Json.NET (Newtonsoft)을 사용하여 빈 배열을 JSON에서 XML로 변환

  5. 5

    Newtonsoft Json Convert는 json 문자열을 객체로 변환하지 않습니다.

  6. 6

    객체에 대한 C # Newtonsoft JSON

  7. 7

    문자열을 유형으로 변환하는 중 오류-Newtonsoft JSON deserialize

  8. 8

    Newtonsoft.Json.JsonReaderException

  9. 9

    JSON 응답을 통해 반복 Newtonsoft.Json.Linq.JObject C #

  10. 10

    자바의 "org.json"대 C #의 "Newtonsoft.Json.JsonConvert"

  11. 11

    Newtonsoft를 사용하여 json 문자열을 json 배열로 변환하려면 어떻게해야합니까?

  12. 12

    Json Newtonsoft Jarray 빌드

  13. 13

    How to DeserializeObject with Newtonsoft.Json?

  14. 14

    Newtonsoft 사용자 정의 Json 변환기 문자열 배열을 쉼표로 구분 된 문자열 WebApi 2

  15. 15

    .net Core 3.1 Newtonsoft.Json은 dictionary <int, string> 키를 문자열로 변환합니다.

  16. 16

    암시 적으로 'Newtonsoft.Json.Linq.JObject'형식을 'System.Collections.Generic.IEnumerable <Employee>'로 변환 할 수 없습니다.

  17. 17

    NewtonSoft.Json이 모두 null을 반환합니다.

  18. 18

    C # MVC 컨트롤 Newtonsoft.json 직렬화

  19. 19

    NewtonSoft를 사용한 C # Chart.js 및 JSON

  20. 20

    C # Newtonsoft JSON 맵 속성을 배열 하위 항목으로

  21. 21

    JSON을 C # 복합 개체로 변환

  22. 22

    Newtonsoft 변경 JSON 케이스 비활성화

  23. 23

    C #에서 Newtonsoft Json.NET을 사용하여 JSON 역 직렬화

  24. 24

    Newtonsoft.JSON을 사용하여 C #으로 Json 문자열 역 직렬화

  25. 25

    JSON을 변경하지 않고 JSON 배열의 NewtonSoft Inheretance 역 직렬화

  26. 26

    JSON 날짜를 C # datetime 변수로 변환

  27. 27

    C # Newtonsoft.Json 최상위 수준 만 역 직렬화 하시겠습니까?

  28. 28

    newtonsoft를 사용하여 VB.NET/C#에서 Json 파일로드

  29. 29

    C # Newtonsoft.json DefaultContractResolver IValueProvider를 사용하여 데이터 충돌 대체

뜨겁다태그

보관