I get all JSON data to my string, but I wanna get item by item, because I need to add my items to database..
static void Main()
{
string res = getItems.getItemsApi();
Item i = JsonConvert.DeserializeObject<Item>(res);
string json = JsonConvert.SerializeObject(i);
}
CLASS: Item
namespace Api
{
public class Currency
{
public int ID { get; set; }
public string Name { get; set; }
public string ResourceUrl { get; set; }
}
public class RevenueAccountDomestic
{
public int ID { get; set; }
public string Name { get; set; }
public string ResourceUrl { get; set; }
}
public class RevenueAccountEU
{
public int ID { get; set; }
public string Name { get; set; }
public string ResourceUrl { get; set; }
}
public class RevenueAccountOutsideEU
{
public int ID { get; set; }
public string Name { get; set; }
public string ResourceUrl { get; set; }
}
public class Item
{
//public int ItemId { get; set; }
public string Name { get; set; }
public string Code { get; set; }
//public string EANCode { get; set; }
//public string Description { get; set; }
public string ItemType { get; set; }
public string UnitOfMeasurement { get; set; }
public VatRate VatRate { get; set; }
public mMApiFkField VatRate { get; set; }
public double Price { get; set; }
public double RebatePercent { get; set; }
public string Usage { get; set; }
public Currency Currency { get; set; }
public RevenueAccountDomestic RevenueAccountDomestic { get; set; }
public RevenueAccountEU RevenueAccountEU { get; set; }
public RevenueAccountOutsideEU RevenueAccountOutsideEU { get; set; }
//public object StocksAccount { get; set; }
//public string RecordDtModified { get; set; }
//public string RowVersion { get; set; }*/
}
}
My output:
string res=
{
"Rows": [
{
"ItemId": 2683406,
"Title": "Izdelava etiket",
"Code": "#75603",
"UnitOfMeasurement": "",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.46,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683407,
"Title": "Fotografija 10 x1 3",
"Code": "",
"UnitOfMeasurement": "kos",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.22,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683408,
"Title": "Digitalna fotografija 10 x 15",
"Code": "",
"UnitOfMeasurement": "kos",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.45,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683409,
"Title": "Fotografija 9x13",
"Code": "",
"UnitOfMeasurement": "kos",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.2,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683410,
"Title": "Digitalna fotografija 9 x 13",
"Code": "",
"UnitOfMeasurement": "kos",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.4,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683411,
"Title": "Fotokopija A4",
"Code": "",
"UnitOfMeasurement": "kos",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0.1,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683442,
"Title": "Snemanje oglasnih sporočil",
"Code": "",
"UnitOfMeasurement": "",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683443,
"Title": "storitev",
"Code": "",
"UnitOfMeasurement": "",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 0,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683444,
"Title": "POSLOVNO SVETOVANJE",
"Code": "",
"UnitOfMeasurement": "ura",
"ItemType": "S",
"VatRate": {
"ID": 36,
"Name": "S",
"ResourceUrl": "/api/orgs/138657/vatrates/36"
},
"Price": 30,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
},
{
"ItemId": 2683445,
"Title": "Obračun provizije po pogodbi za opravljene storitve zavarovalniškega zastopanja",
"Code": "",
"UnitOfMeasurement": null,
"ItemType": "S",
"VatRate": {
"ID": 29,
"Name": "O",
"ResourceUrl": "/api/orgs/138657/vatrates/29"
},
"Price": 0,
"Currency": {
"ID": 7,
"Name": "EUR",
"ResourceUrl": "/api/orgs/138657/currencies/7"
},
"RevenueAccountDomestic": {
"ID": 41636584,
"Name": "Prihodki od prodaje storitev na domačem trgu",
"ResourceUrl": "/api/orgs/138657/accounts/41636584"
},
"RevenueAccountOutsideEU": {
"ID": 41636592,
"Name": "Prihodki od prodaje storitev na trgu izven EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636592"
},
"RevenueAccountEU": {
"ID": 41636591,
"Name": "Prihodki od prodaje storitev na trgu EU",
"ResourceUrl": "/api/orgs/138657/accounts/41636591"
},
"StocksAccount": null
}
],
"TotalRows": 100,
"CurrentPageNumber": 1,
"PageSize": 10
}
string json=
{
"ItemId": 0,
"Name": null,
"Code": null,
"ItemType": null,
"UnitOfMeasurement": null,
"VatRate": null,
"Price": 0,
"RebatePercent": 0,
"Usage": null,
"Currency": null,
"RevenueAccountDomestic": null,
"RevenueAccountEU": null,
"RevenueAccountOutsideEU": null
}
please help me
RootObject newRow = new RootObject(); newRow.Rows[0].Name="sdaad"; but i get error: Additional information: Object reference not set to an instance of an object. in this line: newRow.Rows[0].Name="sdaad"; Can anyone know what is wrong? – devx Sep 30 '15 at 11:44