jak pobrac liste z tego jsona(newtonsoft)?

Odpowiedz Nowy wątek
2018-10-27 21:18
0

Witam mam problem z pobraniem listy obiektow z tego jsona:

Hello i have problem with getting list of companies from this json:

{"result":[{"ID":"2","COMPANY_TYPE":"CUSTOMER","TITLE":"test","LOGO":null,"LEAD_ID":"6","HAS_PHONE":"Y","HAS_EMAIL":"Y","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":"","INDUSTRY":"IT","REVENUE":"0","CURRENCY_ID":"PLN","EMPLOYEES":"EMPLOYEES_1","COMMENTS":"","DATE_CREATE":"2018-06-22T17:06:25+03:00","DATE_MODIFY":"2018-10-22T13:42:07+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":null,"ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"4","COMPANY_TYPE":"CUSTOMER","TITLE":"Test","LOGO":null,"LEAD_ID":null,"HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":"","INDUSTRY":"IT","REVENUE":"0","CURRENCY_ID":"PLN","EMPLOYEES":"EMPLOYEES_1","COMMENTS":"","DATE_CREATE":"2018-10-11T15:44:33+03:00","DATE_MODIFY":"2018-10-11T15:44:33+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":null,"ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"6","COMPANY_TYPE":null,"TITLE":"Nowy go\u015b\u0107 (11.10.2018 20:44:39)","LOGO":null,"LEAD_ID":"8","HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":null,"INDUSTRY":null,"REVENUE":null,"CURRENCY_ID":null,"EMPLOYEES":null,"COMMENTS":null,"DATE_CREATE":"2018-10-11T21:46:33+03:00","DATE_MODIFY":"2018-10-11T21:46:33+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":null,"ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"8","COMPANY_TYPE":"CUSTOMER","TITLE":"Testowa","LOGO":null,"LEAD_ID":null,"HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":"","INDUSTRY":"IT","REVENUE":"0","CURRENCY_ID":"PLN","EMPLOYEES":"EMPLOYEES_1","COMMENTS":"","DATE_CREATE":"2018-10-17T16:50:27+03:00","DATE_MODIFY":"2018-10-17T16:50:27+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":null,"ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"10","COMPANY_TYPE":null,"TITLE":"Postgres siemaszko","LOGO":null,"LEAD_ID":"10","HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":null,"INDUSTRY":null,"REVENUE":null,"CURRENCY_ID":null,"EMPLOYEES":null,"COMMENTS":"davdwqvdvw1dv1w","DATE_CREATE":"2018-10-17T17:08:42+03:00","DATE_MODIFY":"2018-10-17T17:08:42+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":"123","ADDRESS_2":"123","ADDRESS_CITY":"123","ADDRESS_POSTAL_CODE":"123","ADDRESS_REGION":"123","ADDRESS_PROVINCE":"123","ADDRESS_COUNTRY":"123","ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"12","COMPANY_TYPE":null,"TITLE":"1","LOGO":null,"LEAD_ID":"12","HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":null,"INDUSTRY":null,"REVENUE":null,"CURRENCY_ID":null,"EMPLOYEES":null,"COMMENTS":"","DATE_CREATE":"2018-10-22T13:26:04+03:00","DATE_MODIFY":"2018-10-22T13:26:04+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":null,"ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null},{"ID":"14","COMPANY_TYPE":null,"TITLE":"1wdc1wc1wdcc","LOGO":null,"LEAD_ID":"14","HAS_PHONE":"N","HAS_EMAIL":"N","HAS_IMOL":"N","ASSIGNED_BY_ID":"1","CREATED_BY_ID":"1","MODIFY_BY_ID":"1","BANKING_DETAILS":null,"INDUSTRY":null,"REVENUE":null,"CURRENCY_ID":null,"EMPLOYEES":null,"COMMENTS":"","DATE_CREATE":"2018-10-22T13:39:50+03:00","DATE_MODIFY":"2018-10-22T13:39:50+03:00","OPENED":"Y","IS_MY_COMPANY":"N","ORIGINATOR_ID":null,"ORIGIN_ID":null,"ORIGIN_VERSION":null,"ADDRESS":"1wcd1wdcw","ADDRESS_2":null,"ADDRESS_CITY":null,"ADDRESS_POSTAL_CODE":null,"ADDRESS_REGION":null,"ADDRESS_PROVINCE":null,"ADDRESS_COUNTRY":null,"ADDRESS_COUNTRY_CODE":null,"ADDRESS_LEGAL":null,"REG_ADDRESS":null,"REG_ADDRESS_2":null,"REG_ADDRESS_CITY":null,"REG_ADDRESS_POSTAL_CODE":null,"REG_ADDRESS_REGION":null,"REG_ADDRESS_PROVINCE":null,"REG_ADDRESS_COUNTRY":null,"REG_ADDRESS_COUNTRY_CODE":null,"UTM_SOURCE":null,"UTM_MEDIUM":null,"UTM_CAMPAIGN":null,"UTM_CONTENT":null,"UTM_TERM":null}],"total":7,"time":{"start":1540665202.9554,"finish":1540665203.0049,"duration":0.049538850784302,"processing":0.0094828605651855,"date_start":"2018-10-27T21:33:22+03:00","date_finish":"2018-10-27T21:33:23+03:00"}}

My Classes:


    public class Result
{
    public string ID { get; set; }
    public string COMPANY_TYPE { get; set; }
    public string TITLE { get; set; }
    public object LOGO { get; set; }
    public string LEAD_ID { get; set; }
    public string HAS_PHONE { get; set; }
    public string HAS_EMAIL { get; set; }
    public string HAS_IMOL { get; set; }
    public string ASSIGNED_BY_ID { get; set; }
    public string CREATED_BY_ID { get; set; }
    public string MODIFY_BY_ID { get; set; }
    public string BANKING_DETAILS { get; set; }
    public string INDUSTRY { get; set; }
    public string REVENUE { get; set; }
    public string CURRENCY_ID { get; set; }
    public string EMPLOYEES { get; set; }
    public string COMMENTS { get; set; }
    public DateTime DATE_CREATE { get; set; }
    public DateTime DATE_MODIFY { get; set; }
    public string OPENED { get; set; }
    public string IS_MY_COMPANY { get; set; }
    public object ORIGINATOR_ID { get; set; }
    public object ORIGIN_ID { get; set; }
    public object ORIGIN_VERSION { get; set; }
    public string ADDRESS { get; set; }
    public string ADDRESS_2 { get; set; }
    public string ADDRESS_CITY { get; set; }
    public string ADDRESS_POSTAL_CODE { get; set; }
    public string ADDRESS_REGION { get; set; }
    public string ADDRESS_PROVINCE { get; set; }
    public string ADDRESS_COUNTRY { get; set; }
    public object ADDRESS_COUNTRY_CODE { get; set; }
    public object ADDRESS_LEGAL { get; set; }
    public object REG_ADDRESS { get; set; }
    public object REG_ADDRESS_2 { get; set; }
    public object REG_ADDRESS_CITY { get; set; }
    public object REG_ADDRESS_POSTAL_CODE { get; set; }
    public object REG_ADDRESS_REGION { get; set; }
    public object REG_ADDRESS_PROVINCE { get; set; }
    public object REG_ADDRESS_COUNTRY { get; set; }
    public object REG_ADDRESS_COUNTRY_CODE { get; set; }
    public object UTM_SOURCE { get; set; }
    public object UTM_MEDIUM { get; set; }
    public object UTM_CAMPAIGN { get; set; }
    public object UTM_CONTENT { get; set; }
    public object UTM_TERM { get; set; }
}

public class Time
{
    public double start { get; set; }
    public double finish { get; set; }
    public double duration { get; set; }
    public double processing { get; set; }
    public DateTime date_start { get; set; }
    public DateTime date_finish { get; set; }
}

public class RootObject
{
    public List<Result> result { get; set; }
    public int total { get; set; }
    public Time time { get; set; }
}

Czy ktos może mnie nakierować? Dziękuję

Pozostało 580 znaków

2018-10-27 22:00
0

Jak masz Visual Studio:
Skopiuj JSON'a do schowka (ctrl + c), kliknij Edit -> Paste Special -> Paste JSON as classes.

A wcześniej wejdź sobie na jsonlint i sprawdź czy ten json jest poprawny.

Pozostało 580 znaków

2018-10-27 23:33
0

mam juz klasy stworzone i co dalej ?

Pozostało 580 znaków

2018-10-28 00:42
0

Jak już masz zawartość tego JSON-a w zmiennej string "json" to robisz zwykłe:

var obj = JsonConvert.DeserializeObject<RootObject>(json);

I w zmiennej obj masz wszystko.

Pozostało 580 znaków

Odpowiedz
Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0