Cameron Wilby Cameron Wilby - 3 months ago 11
C# Question

How would I parse the following JSON string using RestSharp?

I am writing a C# wrapper for the SalesforceIQ platform and I'm having trouble figuring out the best way (or any way) to parse the following JSON string in C# - specifically the

fieldValues
property, which the API specifies as:


A collection of Field definitions that are associated with the List.
These Fields are stored as an array of Field objects, with each Field
a mapping of an id, display name, and (in the case of pick list
fields) an array of listOptions. The Field’s id is a string containing
the index of that field in the order they were created; these ids are
used to map fields to their values within List Items. The listOptions
property maps to an array of option objects, each containing an option
id and the display value of that option. When setting the value of
these types of fields, these list fields need to be set to this ID
rather than their display value.


My question is - what classes/object structure can I use in C# to model this
fieldValues
data?

{
"id": "<masked>",
"listId": "<masked>",
"version": 1,
"createdDate": 1470089225761,
"modifiedDate": 1470095205436,
"name": "<masked>",
"accountId": "<masked>",
"contactIds": [
"<masked>"
],
"fieldValues": {
"0": [
{
"raw": "2"
}
],
"1": [
{
"raw": "<masked>"
}
],
"4": [
{
"raw": "35"
}
],
"process_close_date": [
{
"raw": "<masked>"
}
],
"process_created_date": [
{
"raw": "<masked>"
}
]
},
"linkedItemIds": {}
}

ubi ubi
Answer

What about something like

IDictionary<string, IEnumerable<Field>> fieldValues;

where

public class Field 
{
    public string raw { get; set; }
}