1

First of all, I apologize for the vague title or any other incorrect terminology. I'm new to working with JSON and multi-layered (multi-dimensional?) formats aren't talked about much in online tutorials.

My question is, using this data:

Lot = "ABC" infoA = "1.0" infoB = "2.0" 

I'm trying to return the following JSON format from a GET request using asp.net web api:

{ "ABC" : { infoA: "1.0", infoB: "2.0" } } 

My model is setup as below:

public class LotHeader { public string LotID { get; set; } public Lot LotInfo { get; set; } } public class Lot { public string infoA{ get; set; } public string infoB { get; set; } } 

And my controller looks like this: enter image description here

Currently, I'm getting the following output:

{"LotID":"ABC", "LotInfo": {"infoA":"1.0","infoB":"2.0"} } 

Is it possible to get the desired output? Thanks for any help.

1 Answer 1

2

To get your desired output, you can populate a Dictionary<string, Lot>:

var response = new Dictionary<string, Lot>(); response[lot.LotID] = lot.LotInfo; return Ok(response); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.