I am trying to process multiple files and move their data to a SharePoint list. I totally agree with the SharePoint component of my request, but I'm struggling to wrap my head around accepting JSON and executing C # statements against it.
The JSON I'm working with is in the following format:
{
"details": {
"persona": "jdfh sjahfj ashd",
"firstName": "difdfsdfh",
"surname": "safasfjhgfasdf",
"email": "dfashfjsahf@dfjhdfjhsd.com",
"phone": "3256545 421",
"organisation": "dsfhjafd gas gdf",
"department": "hsagfhsdgahjf",
"address": {
"street": "11/338 shjafg ash fg",
"suburb": "gsagfghasf",
"postcode": "4006"
},
"questions": {
"iAmA": "fhsahjfsajhd df as",
"iWorkAtA": "",
"iAmSeekingFor": "ahshfjgsfggdh",
"iAmAMemberOf": "dafjksfhdh",
"furtherInfoOptIn": true,
"newsletterOptIn": false,
"privacyCollection": true
}
},
"orders": [
{
"name": "Business Cards",
"quantity": 8
},
{
"name": "QUITLINE",
"quantity": 5
}
]
}
Based on this StackExchange request I tried to create a class to deserialize my content using the following:
var des = (ResourceOrdersJSONEntity)Newtonsoft.Json.JsonConvert.DeserializeObject(sampleJSON, typeof(ResourceOrdersJSONEntity));
This does not work for me, and I suspect that I am looking at a completely wrong path. What do I need to know about to take JSON and wrap linq expressions around it for processing in SharePoint?
The error I get is:
JSON (, { "name": "value" }) 'System.Collections.Generic.List`1
, JSON JSON (, [1,2,3]) , .NET. type (, integer, ), JSON. JsonObjectAttribute , JSON.
, , , , , . , .
, :
ResourceOrdersJSONEntity { public List Details {get; ; } {get; ; } }
public class ResourceOrdersDetailsEntity
{
public string Persona { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Organisation { get; set; }
public string Department { get; set; }
public ResourceOrdersAddressEntity Address { get; set; }
public ResourceOrdersQuestionsEntity Questions { get; set; }
}
public class ResourceOrdersAddressEntity
{
public string Street { get; set; }
public string Suburb { get; set; }
public string Postcode { get; set; }
}
public class ResourceOrdersQuestionsEntity
{
public string IAma { get; set; }
public string IWorkAtA { get; set; }
public string IAmSeekingFor { get; set; }
public string IAmAMemberFor { get; set; }
public string FurtherInfoOptIn { get; set; }
public string NewsLetterOptIn { get; set; }
public string PrivacyCollection { get; set; }
}
public class ResourceOrdersQuantityEntity
{
public string Name { get; set; }
public int Quantity { get; set; }
}