0

I have a Stack of ids of unknown size(set dynamically during run) that i want to serialize but am unsure how to.

The format MUST match this:

"items":["<ITEM1 ID>", "<ITEM2 ID>"]
"items":["<ITEM1 ID>", "<ITEM2 ID>", "<ITEM3 ID>"]
"items":["<ITEM1 ID>", "<ITEM2 ID>", "<ITEM3 ID>", "<ITEM4 ID>"]

the full JSON request is as follows:

{"data":[{"Action":"<ACTION HERE>","sellInOnePiece":false,"items":["<ITEM1 ID>", "<ITEM2 ID>"],"requirements":[{"_tpl":"<ID HERE>","count":<COUNT HERE>,"level":0,"side":0,"onlyFunctional":false}]}],"tm":2}

The thing is, i dont know how many items there will be. It could be 1, it could be 100. How can i dynamically add the interior input of "items" based on the number of items in my stack?

Ignition K6
  • 147
  • 1
  • 1
  • 14
  • 1
    JsonConvert.SerializeObject - will this not help? it can serialize your object regardless of the length but you may need to do some work on the format – Ali Dec 10 '19 at 23:24
  • 1
    Format show is not JSON as there is no `,` between lines... Or post shows 3 separate examples asking how to serialize array from JSON? Very unclear what you have problem with - maybe re-reading your search https://www.bing.com/search?q=c%23+json+string+array could help you clarify with [edit] where you are stuck coding it up... – Alexei Levenkov Dec 10 '19 at 23:32
  • 1
    Please show the desired JSON object in its entirety, this is missing formatting and is invalid JSON – robbpriestley Dec 10 '19 at 23:35
  • added full json query for clarity – Ignition K6 Dec 10 '19 at 23:41
  • If you are deserializing a `Stack`, most JSON serializers will reverse the stack during a serialization/deserialization round trip. If you are using Json.NET, then to fix this problem see [JsonConvert.Deserializer indexing issues](https://stackoverflow.com/a/39481981/3744182). – dbc Dec 11 '19 at 04:27

0 Answers0