'Turn an array into a single object
I have the following array
[
{"item":"pageTitle", "value":"My Page Title"},
{"item":"instructionalText", "value":"My Instruction Text"},
{"item":"continueButton", "value":"Continue"}
]
And I want to convert to something like this? Maybe?
{"pageTitle":"My Page Title", "InstructionalText":"My Instructional Text", etc...}
My end goal is to be able to reference it like myContent.pageTitle and get My Page Title in return.
My Model:
public class GiftAidContent
{
[JsonPropertyAttribute("PageTitle")]
public string PageTitle { get; set; }
[JsonPropertyAttribute("InstrText")]
public string InstrText { get; set; }
[JsonPropertyAttribute("AcceptBtnText")]
public string AcceptBtnText { get; set; }
[JsonPropertyAttribute("DeclineBtnText")]
public string DeclineBtnText { get; set; }
}
Using the dictionary as idle_mind suggested in comment, I now have this.
content
Count = 4
[0]: {[page_title, Gift Aid]}
[1]: {[instructional_text, Lorem ipsum dolor sit amet.]}
[2]: {[continue_btn, Continue]}
[3]: {[cancel_btn, Cancel]}
Source that has current data.
List<GlobalContent> listOfGlobalContentsWork
public class GiftAidObject
{
[JsonPropertyAttribute("isGiftAidEligible")]
public bool isGiftAidEligible { get; set; }
public List<GlobalContent> GlobalContentList { get; set; }
public string ErrorText { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|