Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I have the following problem.

I'm trying to download the data via the Shopware API, convert it to JSON and then display it in a list view.

Unfortunately I can only get 1000 items using JsonConvert.DeserializeObject.

C#
ArtikelC.AJson A = JsonConvert.DeserializeObject(responseFromServer, jsonSettings);

for(int i = 0; i < A.data.Count; i++)
{
   ListViewItem lvi = new ListViewItem();

   lvi.Text = A.data[i].id.ToString();
   lvi.SubItems.Add(A.data[i].mainDetail.ToString().Split(new string[] { "," }, 
   StringSplitOptions.None)[3].Replace("\"", "").Replace("number: ", ""));
   lvi.SubItems.Add(A.data[i].name);

   listView1.Items.Add(lvi);
}


Response-Length: 4.382.212
data.Count (JSON): 1000
Total Count API: 48.074

I hope someone can help me with this Problem :)

Classes:

C#
public class clsAData
{
    public int id { get; set; }
    public int mainDetailId { get; set; }
    public int supplierId { get; set; }
    public int taxId { get; set; }
    public int priceGroupId { get; set; }
    public int filterGroupId { get; set; }
    public int configuratorSetId { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public string descriptionLong { get; set; }
    public DateTime added { get; set; }
    public bool active { get; set; }
    public int pseudoSales { get; set; }
    public bool highlight { get; set; }
    public string keywords { get; set; }
    public string metaTitle { get; set; }
    public DateTime changed { get; set; }
    public bool priceGroupActive { get; set; }
    public bool lastStock { get; set; }
    public bool crossBundleLook { get; set; }
    public bool notification { get; set; }
    public string template { get; set; }
    public int mode { get; set; }
    public DateTime availableFrom { get; set; }
    public DateTime availableTo { get; set; }
    public object mainDetail { get; set; }
    public object tax { get; set; }
    public object propertyValue { get; set; }
    public object supplier { get; set; }
    public object propertyGroup { get; set; }
    public object[] customerGroups { get; set; }
    public object[] images { get; set; }
    public object configuratorSet { get; set; }
    public object[] links { get; set; }
    public object[] downloads { get; set; }
    public object[] categories { get; set; }
    public object[] similar { get; set; }
    public object[] related { get; set; }
    public object[] details { get; set; }
    public object[] translations { get; set; }
}

public class AJson
{
   [JsonProperty("data")]
   public List data { get; set; }

   [JsonProperty("total")]
   public int total { get; set; }
}


What I have tried:

XML
<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647"/>
      </webServices>
    </scripting>
</system.web.extensions>
Posted
Updated 4-Apr-22 13:19pm
v2
Comments
PIEBALDconsult 4-Apr-22 19:20pm    
Yeah, I would suspect that some form of paging is going on.

1 solution

Check the data you receive - neither JSON nor Newtonsoft implement a limit on the data item count, so the chances are that the data originator is.
1000 items is a "human number" rather than a "computer" one, and it's unlikely (a thousand to one, literally) that a shop will contain exactly that number of products.

The most likely reason is that the originator doesn't supply the full information, or requires some kind of parameter to provide more than 1000 items.

So the first thing to do is save the JSON and see how many items it holds. If it's exactly 1000 and you are sure it should be more, you need to talk to the originator - they are the only ones who can help you!

[edit]
Having said that, I just noticed what you are doing with the data - and it's very silly. Never throw large amounts of data at a user, it makes your site pretty much impossible to use, and most users will just give up and go elsewhere. Only show up to about 100 items at a time - less is better - and provide paging, searching, and filtering to let the user find what he wants easily. And it will slow your site to a crawl from a user perspective as well!
[/edit]
 
Share this answer
 
v2
Comments
Marvin Kriebel 4-Apr-22 5:25am    
I thank you! That was probably my mistake then. I've wanted to check the output before, but figured it would be constrained by JSON.

I don't intend to do what you think. I'm making the tool just for myself so I can also make PUT requests to make changes in a larger sense.

The users themselves are not affected, but thanks for the tip anyway!

I'll look at the API again and see if I can get more. Thank you for your time!

It saves the total, but only gives up 1000 results, I could have seen that via Postman, but I was too busy at work because I only do it on the side to simplify my work. :) Thank you!

[edit]
U can change the Limit in Shopware API with: &limit=1500

Sooo stupid...
[/edit]
OriginalGriff 4-Apr-22 6:07am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900