阅读所有json数据

时间:2015-10-01 11:24:33

标签: c# json http-get

我在阅读数据方面遇到了问题。我只能读取100个项目(行)中的10个,因为它是分页的。有谁知道如何阅读所有项目?

string res = getItems.getItemsApi();
ItemsPage ia = JsonConvert.DeserializeObject<ItemsPage>(res);

String Name;
String value = "";

for (int cou = 0; cou < ia.PageSize; cou++)
{
    ia.Rows[cou].GetType().GetProperties().ToList().ForEach(b =>
    {
        Name = b.Name.ToString();

        switch (Name)
        {
            case "1":
            case "ItemId":
                value = ia.Rows[cou].ItemId.ToString();

                break;
            case "2":
            case "Title":
                value = ia.Rows[cou].Title.ToString();
                break;
            case "3":
            case "Code":
                value = ia.Rows[cou].Code.ToString();
                break;
            case "4":
            case "UnitOfMeasurement":
                value = ia.Rows[cou].UnitOfMeasurement;
                break;
            case "5":
            case "ItemType":
                value = ia.Rows[cou].ItemType.ToString();
                break;
            case "6":
            case "VatRate":
                value = ia.Rows[cou].VatRate.Name;
                break;
            case "7":
            case "Price":
                value = ia.Rows[cou].Price.ToString();
                break;
            case "8":
            case "Currency":
                value = ia.Rows[cou].Currency.Name.ToString();
                break;
            case "9":
            case "RevenueAccountDomestic":
                value = ia.Rows[cou].RevenueAccountDomestic.ID.ToString();
                break;
            case "10":
            case "RevenueAccountOutsideEU":
                value = ia.Rows[cou].RevenueAccountOutsideEU.ID.ToString();
                break;
            case "11":
            case "RevenueAccountEU":
                value = ia.Rows[cou].RevenueAccountEU.ID.ToString();
                break;
            case "12":
            /*case "StocksAccount":
                Console.WriteLine(b + "     " + ia.Rows[cou].StocksAccount);
                value = ia.Rows[cou].StocksAccount.ToString();
                break;*/

            default:
                //Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
                break;
        }
public class VatRate
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string ResourceUrl { get; set; }
}

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 RevenueAccountOutsideEU
{
    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 Row
{
    public int ItemId { get; set; }
    public string Title { get; set; }
    public string Code { get; set; }
    public string UnitOfMeasurement { get; set; }
    public string ItemType { get; set; }
    public VatRate VatRate { get; set; }
    public double Price { get; set; }
    public Currency Currency { get; set; }
    public RevenueAccountDomestic RevenueAccountDomestic { get; set; }
    public RevenueAccountOutsideEU RevenueAccountOutsideEU { get; set; }
    public RevenueAccountEU RevenueAccountEU { get; set; }
    //public object StocksAccount { get; set; }
}

public class ItemsPage
{
    public List<Row> Rows { get; set; }
    public int TotalRows { get; set; }
    public int CurrentPageNumber { get; set; }
    public int PageSize { get; set; }
}

如果有人知道如何阅读所有数据页面,请回答我......

thx

    public static string getItemsApi()
    {
        bool apiMethodUrl = ConnectApi.GetApiResultContent(apiMethodUrlItems, Program.GetApiAccessToken(), out status, out result);

    return result;
    }
    public static HttpStatusCode GetApiSelectByIdStatusCode(string apiMethodUrl, string accessToken)
    {
        HttpStatusCode responseCode = HttpStatusCode.Unused;
        string resultContentStr;

        GetApiResultContent(apiMethodUrl, accessToken, out responseCode, out resultContentStr);

        return responseCode;
    }

0 个答案:

没有答案