When I create the following event using the graph SDK, the first instance of the recurring event isn't created until May 4th, 2021:
var tmpEvent = new Microsoft.Graph.Event
{
Start = new Microsoft.Graph.DateTimeTimeZone
{
DateTime = "2020-05-04T16:00:00",
TimeZone = "Central Standard Time"
},
End = new Microsoft.Graph.DateTimeTimeZone
{
DateTime = "2020-05-04T17:00:00",
TimeZone = "Central Standard Time"
},
Subject = "Bi-Annual Event",
Body = new Microsoft.Graph.ItemBody
{
Content = "Trying to make a bi-annual event",
ContentType = Microsoft.Graph.BodyType.Text
},
Attendees = new List<Microsoft.Graph.Attendee>{
new Microsoft.Graph.Attendee
{
EmailAddress = new Microsoft.Graph.EmailAddress
{
Address = "test.email.123#someTestDomain.org"
},
Type = Microsoft.Graph.AttendeeType.Required
}
},
Location = new Microsoft.Graph.Location
{
DisplayName = "the office"
},
Recurrence = new PatternedRecurrence
{
Pattern = new RecurrencePattern
{
DayOfMonth = 4,
Interval = 2,
Month = 5,
Type = RecurrencePatternType.AbsoluteYearly
},
Range = new RecurrenceRange
{
StartDate = new Date(2020, 5, 4),
Type = RecurrenceRangeType.NoEnd
}
}
};
var graphClient = await MicrosoftAuthenticationProvider.GetGraphClient(CALENDAR_CLIENT_ID, CALENDAR_CLIENT_SECRET, CALENDAR_REDIRECT_URI, CALENDAR_ACCESS_SCOPES, RefreshToken);
var savedEvent = await graphClient.Me.Events
.Request()
.AddAsync(tmpEvent);
Here is what the recurrence looks like in Outlook:
enter image description here
When I resave the recurrence/series in Outlook, the event appears (correctly) on May 4th, 2020.
Is this a bug with the graph SDK?
UPDATE:
Here is the body request I am sending:
{
"OriginalStartTimeZone": null,
"OriginalEndTimeZone": null,
"ResponseStatus": null,
"ICalUId": null,
"ReminderMinutesBeforeStart": null,
"IsReminderOn": null,
"HasAttachments": null,
"Subject": "Bi-Annual Event",
"Body": {
"ContentType": 0,
"Content": "Trying to make a bi-annual event",
"AdditionalData": null,
"ODataType": "microsoft.graph.itemBody"
},
"BodyPreview": null,
"Importance": null,
"Sensitivity": null,
"Start": {
"DateTime": "2020-05-04T16:00:00",
"TimeZone": "Central Standard Time",
"AdditionalData": null,
"ODataType": "microsoft.graph.dateTimeTimeZone"
},
"OriginalStart": null,
"End": {
"DateTime": "2020-05-04T17:00:00",
"TimeZone": "Central Standard Time",
"AdditionalData": null,
"ODataType": "microsoft.graph.dateTimeTimeZone"
},
"Location": {
"DisplayName": "the office",
"LocationEmailAddress": null,
"Address": null,
"LocationUri": null,
"Coordinates": null,
"LocationType": null,
"UniqueId": null,
"UniqueIdType": null,
"AdditionalData": null,
"ODataType": "microsoft.graph.location"
},
"Locations": null,
"IsAllDay": null,
"IsCancelled": null,
"IsOrganizer": null,
"Recurrence": {
"Pattern": {
"Type": 4,
"Interval": 2,
"Month": 5,
"DayOfMonth": 4,
"DaysOfWeek": null,
"FirstDayOfWeek": null,
"Index": null,
"AdditionalData": null,
"ODataType": "microsoft.graph.recurrencePattern"
},
"Range": {
"Type": 1,
"StartDate": {
"Year": 2020,
"Month": 5,
"Day": 4
},
"EndDate": null,
"RecurrenceTimeZone": null,
"NumberOfOccurrences": null,
"AdditionalData": null,
"ODataType": "microsoft.graph.recurrenceRange"
},
"AdditionalData": null,
"ODataType": "microsoft.graph.patternedRecurrence"
},
"ResponseRequested": null,
"SeriesMasterId": null,
"ShowAs": null,
"Type": null,
"Attendees": [
{
"Status": null,
"Type": 0,
"EmailAddress": {
"Name": null,
"Address": "test.email.123#someTestDomain.org",
"AdditionalData": null,
"ODataType": "microsoft.graph.emailAddress"
},
"AdditionalData": null,
"ODataType": "microsoft.graph.attendee"
}
],
"Organizer": null,
"WebLink": null,
"OnlineMeetingUrl": null,
"IsOnlineMeeting": null,
"OnlineMeetingProvider": null,
"OnlineMeeting": null,
"Attachments": null,
"SingleValueExtendedProperties": null,
"MultiValueExtendedProperties": null,
"Calendar": null,
"Instances": null,
"Extensions": null,
"CreatedDateTime": null,
"LastModifiedDateTime": null,
"ChangeKey": null,
"Categories": null,
"Id": null,
"ODataType": "microsoft.graph.event",
"AdditionalData": null
}
Does your request look different?
Also, I noticed this is only an issue on the desktop client, the events appear normally on the web client
Related
I have json that come from API
Here is part of it
{
"Area": "Werrington, Peterborough",
"MetaData": {
"CanonicalName": "pe4-werrington,peterborough",
"District": "PE4",
"Postcode": "PE46QR",
"Area": "Werrington, Peterborough",
"Latitude": 52.609645,
"Longitude": -0.268349,
"ResultCount": 113,
"SearchedTerms": null
},
"Restaurants": [
{
"Id": 65016,
"Name": "Grill & Krispy",
"UniqueName": "Grill-and-Krispy-pe1",
"Address": {
"City": "Peterborough",
"FirstLine": "20 Westgate",
"Postcode": "PE1 2SY",
"Latitude": 52.574544,
"Longitude": -0.243271
},
"City": "Peterborough",
"Postcode": "PE1 2SY",
"Latitude": 0.0,
"Longitude": 0.0,
"Rating": {
"Count": 1726,
"Average": 4.23,
"StarRating": 4.23
},
"RatingStars": 4.23,
"NumberOfRatings": 1726,
"RatingAverage": 4.23,
"Description": "",
"Url": "https://www.just-eat.co.uk/restaurants-Grill-and-Krispy-pe1",
"LogoUrl": "http://d30v2pzvrfyzpo.cloudfront.net/uk/images/restaurants/65016.gif",
"IsTestRestaurant": false,
"IsHalal": false,
"IsNew": false,
"ReasonWhyTemporarilyOffline": "",
"DriveDistance": 2.6,
"DriveInfoCalculated": true,
"IsCloseBy": false,
"OfferPercent": 20.0,
"NewnessDate": "2016-11-03T12:58:00",
"OpeningTime": "2020-09-02T09:30:00Z",
"OpeningTimeUtc": null,
"OpeningTimeIso": "2020-09-02T09:30:00",
"OpeningTimeLocal": "2020-09-02T10:30:00",
"DeliveryOpeningTimeLocal": "2020-09-01T12:00:00",
"DeliveryOpeningTime": "2020-09-01T11:00:00Z",
"DeliveryOpeningTimeUtc": null,
"DeliveryStartTime": "2020-09-01T11:00:00Z",
"DeliveryTime": null,
"DeliveryTimeMinutes": null,
"DeliveryWorkingTimeMinutes": 40,
"DeliveryEtaMinutes": {
"Approximate": null,
"RangeLower": 30,
"RangeUpper": 45
},
"IsCollection": true,
"IsDelivery": true,
"IsFreeDelivery": false,
"IsOpenNowForCollection": true,
"IsOpenNowForDelivery": true,
"IsOpenNowForPreorder": false,
"IsOpenNow": true,
"IsTemporarilyOffline": false,
"DeliveryMenuId": 230763,
"CollectionMenuId": null,
"DeliveryZipcode": null,
"DeliveryCost": 0.0,
"MinimumDeliveryValue": 0.0,
"SecondDateRanking": 0.0,
"DefaultDisplayRank": 0,
"SponsoredPosition": 0,
"SecondDateRank": 0.0,
"Score": 113.0,
"IsTemporaryBoost": false,
"IsSponsored": true,
"IsPremier": false,
"HygieneRating": null,
"ShowSmiley": false,
"SmileyDate": null,
"SmileyElite": false,
"SmileyResult": null,
"SmileyUrl": null,
"SendsOnItsWayNotifications": false,
"BrandName": "",
"IsBrand": false,
"LastUpdated": "2020-09-01T11:16:19.144899"
}
]
}
I need to get only Restaurants part.
Here is how I try to do this
var baseUrl = "**********";
var client = new RestClient(baseUrl);
var request = new RestRequest($"restaurants/bypostcode/{input.PostCode}", Method.GET);
var response = await client.ExecuteTaskAsync(request);
var searchResult = JsonConvert.DeserializeObject<Restaurant>(response.Content);
And on deserialize I get this
{
"id": 0,
"name": null,
"uniqueName": null,
"address": null,
"city": null,
"postcode": null,
"latitude": 0,
"longitude": 0,
"rating": null,
"ratingStars": 0,
"numberOfRatings": 0,
"ratingAverage": 0,
"description": null,
"url": null,
"logoUrl": null,
"isTestRestaurant": false,
"isHalal": false,
"isNew": false,
"reasonWhyTemporarilyOffline": null,
"driveDistance": 0,
"driveInfoCalculated": false,
"isCloseBy": false,
"offerPercent": 0,
"newnessDate": "0001-01-01T00:00:00",
"openingTime": "0001-01-01T00:00:00",
"openingTimeUtc": null,
"openingTimeIso": "0001-01-01T00:00:00",
"openingTimeLocal": "0001-01-01T00:00:00",
"deliveryOpeningTimeLocal": "0001-01-01T00:00:00",
"deliveryOpeningTime": "0001-01-01T00:00:00",
"deliveryOpeningTimeUtc": null,
"deliveryStartTime": "0001-01-01T00:00:00",
"deliveryTime": null,
"deliveryTimeMinutes": null,
"deliveryWorkingTimeMinutes": 0,
"isCollection": false,
"isDelivery": false,
"isFreeDelivery": false,
"isOpenNowForCollection": false,
"isOpenNowForDelivery": false,
"isOpenNowForPreorder": false,
"isOpenNow": false,
"isTemporarilyOffline": false,
"deliveryMenuId": 0,
"collectionMenuId": null,
"deliveryZipcode": null,
"deliveryCost": 0,
"minimumDeliveryValue": 0,
"secondDateRanking": 0,
"defaultDisplayRank": 0,
"sponsoredPosition": 0,
"secondDateRank": 0,
"score": 0,
"isTemporaryBoost": false,
"isSponsored": false,
"isPremier": false,
"hygieneRating": null,
"showSmiley": false,
"smileyDate": null,
"smileyElite": false,
"smileyResult": null,
"smileyUrl": null,
"sendsOnItsWayNotifications": false,
"brandName": null,
"isBrand": false,
"lastUpdated": "0001-01-01T00:00:00",
"tags": null,
"deliveryChargeBands": null,
"badges": null,
"openingTimes": null,
"serviceableAreas": null
}
How I can fix this?
The JSON you're deserializing is not an instance of Restaurant. It's an instance of an object which has a property called Restaurants which is an array of, presumably, Restaurant objects.
Create that object structure:
public class RestaurantsInfo
{
public IEnumerable<Restaurant> Restaurants { get; set; }
}
And deserialize to that:
var searchResult = JsonConvert.DeserializeObject<RestaurantsInfo>(response.Content);
I have a Json file with couple of fields and I have some problems searching for specific fields.
This is the Json file(I cut it short since the original is huge):
{
"errors": {
"errorCode": 0,
"errorMessage": "",
"errorDescription": null
},
"pagination": {
"recordsReturned": 250,
"totalRecordsFound": 123,
"currentPage": 1,
"recordsPerPage": 250
},
"data": {
"totalDCount": 1713,
"totalValue": "50",
"totalCarats": 60,
"averagePricePerCarat": 21,
"averageDiscount": -0.29,
"dResult": [
{
"color": "H",
"dID": 4693,
"fancyColor": {
"dominantColor": null,
"secondaryColor": null,
"overtones": null,
"intensity": null,
"color1": null,
"color2": null
},
"seller": {
"accountID": 124,
"companyName": "",
"companyCode": " ",
"founded": "",
"address": null,
"telephone": " ",
"fax": null,
"email": null,
"contactPrimaryName": "value",
"city": null,
"state": null,
"country": "USA",
"address1": null,
"address2": null,
"skypeName": null,
"primarySupplierBadge": true,
"ratingPercent": 1.0,
"totalRating": 1.0,
"relatedAccounts": null
},
"shape": "Round",
{
"color": "H",
"dID": 46,
"fancyColor": {
"dominantColor": null,
"secondaryColor": null,
"overtones": null,
"intensity": null,
"color1": null,
"color2": null
},
"seller": {
"accountID": 124,
"companyName": "",
"companyCode": " ",
"founded": "",
"address": null,
"telephone": " ",
"fax": null,
"email": null,
"contactPrimaryName": "value",
"city": null,
"state": null,
"country": "USA",
"address1": null,
"address2": null,
"skypeName": null,
"primarySupplierBadge": true,
"ratingPercent": 1.0,
"totalRating": 1.0,
"relatedAccounts": null
},
"shape": "Round"
}
]
}
}
I wrote a code that should search for "dId" field value under the "dResult". Unfortunately this error comes up (I am using Newtonsoft.Json parser) :
"Newtonsoft.Json.JsonReaderException: Invalid property identifier character: {. Path 'data.dResult[0].shape', line 54, position 11."
A.This is the code I wrote, I would be happy if you could tell me what is the problem ?
B.A second problem that I had is that I need to pick only the "dID" of those that have the "shape" field value as "Round", I didn't figure out a way to do that since I need to go and find a further field while encountering "dId" field .
class Program
{
static void Main(string[] args)
{
string filepath = "../../json1.json";
string result = string.Empty;
string str = string.Empty;
using (StreamReader r = new StreamReader(filepath))
{
var json = r.ReadToEnd();
JObject jObject = JObject.Parse(json);
JToken jUser = jObject["data"];
string jsonString = jUser.ToString();
JObject jObject1 = JObject.Parse(jsonString);
JToken jUser2 = jObject1["dResult"];
string jsonString2 = jUser2.ToString();
JObject jObject2 = JObject.Parse(jsonString2);
foreach (var item in jObject2.Properties())
{
if (item.Name == "dID")
{
str = item.Value.ToString();
result = result + " " + str;
}
}
}
Console.WriteLine(result);
}
}
Reference for the comment I received here (Another Json section, this is under "dResult"):
, {
"dID": 281242,
"seller": {
"accountID": 21321,
"companyName": "RA",
"companyCode": "001",
"founded": "000",
"address": null,
"telephone": "999",
"fax": null,
"email": null,
"contactPrimaryName": "name",
"city": null,
"state": null,
"country": "USA",
"address1": null,
"address2": null,
"skypeName": null,
"primarySupplierBadge": true,
"ratingPercent": 1.0,
"totalRating": 1.0,
"relatedAccounts": null
},
"shape": "Round",
"size": 0.010,
"color": "K",
"fancyColor": {
"dominantColor": null,
"secondaryColor": null,
"overtones": null,
"intensity": null,
"color1": null,
"color2": null
},
You can use the following Linq query to pull the dID values for the Round shapes. However the JSON is not in a correct format.
var jsonStr = File.ReadAllText(Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"example-json.json"));
var parsed = JObject.Parse(jsonStr);
var dIdList = parsed["data"]["dResult"]
.Where(x => x.Value<String>("shape").Equals("round", StringComparison.InvariantCultureIgnoreCase))
.Select(x => x.Value<Int32>("dID"))
.ToList();
And here is the re-formatted JSON (notice the diff on line 52-53), there was a missing } which caused the array to be off:
Once you correct the JSON, by adding this } and run the above Linq query it will return the following result:
Good, luck. Let me know if you need any further assistance.
Once you fix the improperly formatted json data, you can use linq to find the round objects:
var searchResults = from r in jObject["data"]["dResult"]
where r["shape"].ToString() == "Round"
select r;
foreach (var r in searchResults)
{
Console.WriteLine(r["dID"]);
}
I am getting this 'optimized' JSON response from a third party web service presented as follows, I built the type as per the information presented in the keys but the difficulty I am facing is that data is not represented in objects but in arrays, is there a way to automate the building and value mapping of my objects list?
{
"reports": {
"query": {
"keys": [{
"name": "Date",
"type": "date"
}, {
"name": "NetSales",
"type": "price"
}, {
"name": "GrossCash",
"type": "price"
}, {
"name": "GrossCard",
"type": "price"
}, {
"name": "GrossDelivery",
"type": "price"
}, {
"name": "NetFood",
"type": "price"
}, {
"name": "NetDrink",
"type": "price"
}, {
"name": "NetRetail",
"type": "price"
}, {
"name": "Baskets",
"type": "int"
}],
"data": [
[1523577600000, 51924, 11300, 27200, 9900, null, null, null, 8],
[1523404800000, 7434, 2600, 3900, null, null, null, null, 6],
[1523491200000, 18101, 4000, 10100, null, null, null, null, 5],
[1523664000000, 13243, 7400, 6500, null, null, null, null, 3],
[1523750400000, 11718, 7300, null, 5000, null, null, null, 2],
[1523836800000, 16576, 7700, 4800, 4900, null, null, null, 4],
[1524096000000, 20293, 9100, 6000, null, null, null, null, 4]
]
}
},
"api": {
"message": {
"success": {
"202": {
"id": 202,
"title": "Token is valid",
"details": "Token is validated and found valid."
}
}
},
"codeBaseVersion": 1,
"executionTime_milliSeconds": 43
}
}
I ended up with this code but not satisfied with it:
JObject myOpject = JObject.Parse(responseString);
List<JToken> setOfObjects = myOpject["reports"]["query"]["data"].Children().ToList();
var listOfData = new List<Data2>();
foreach (var token in setOfObjects)
{
var myObject = new Data2
{
NetSales = decimal.Parse(token[1].ToString()),
//etc.
};
listOfData.Add(myObject);
}
using the same JToken idea transform the data using the keys to create a new object model and then deserialize that to the strong type desired.
For example, taking a few records you can transform the keys and data to
[
{
"Date": 1523577600000,
"NetSales": 51924,
...
},
{
"Date": 1523404800000,
"NetSales": 7434,
...
},
...
]
The following code attempts to build that using the key index matched to the index of item in data array
JObject myOpject = JObject.Parse(responseString);
List<JToken> keys = myOpject["reports"]["query"]["keys"].Children().ToList();
List<JToken> data = myOpject["reports"]["query"]["data"].Children().ToList();
var array = new JArray();
foreach (var token in data) {
var record = new JObject();
for (var i = 0; i < keys.Count; i++) {
var propertyName = keys[i]["name"].Value<string>();
var propertyValue = token[i];
record[propertyName] = propertyValue;
}
array.Add(record);
}
var listOfData = array.ToObject<List<Data2>>(); // or Data2[], etc
assuming Data2 is your strongly typed model with matching properties.
I'm kinda new so I apologize if I'm not using the correct terminology.
Basically I'm building a .net core web app with an AngularJs component in the frontend to retrieve and display the results from my API's JSON get request.
[Authorize(Roles = "Manager")]
[HttpGet("Clients")]
public async Task<JsonResult> AllClients()
{
IEnumerable<AppUser> Clients = await _userManagerService.GetUsersInRoleAsync("Client");
return Json(listErrorMsg(Clients));
}
The problem i'm having is that the API sends EVERY column of every user, as expected.
[
{
"firstName": "Client2",
"lastName": "2",
"residentialAddress": null,
"residentialSuburb": null,
"residentialPostCode": null,
"residentialCity": null,
"residentialstateTerritory": "NULL",
"postalAddress": null,
"postalSuburb": null,
"postalPostCode": null,
"postalCity": null,
"postalstateTerritory": "NULL",
"lastSync": "0001-01-01T00:00:00",
"accountCreated": "0001-01-01T00:00:00",
"lastVisited": "0001-01-01T00:00:00",
"client": null,
"clientID": null,
"id": "2075c598-5bc3-4f74-a843-ac41e4d0bc36",
"userName": "Client2",
"normalizedUserName": "CLIENT2",
"email": null,
"normalizedEmail": null,
"emailConfirmed": true,
"passwordHash": "AQAAAAEAACcQAAAAELFKxfP2giuEtg8+M4q7Pu2+lpGBDOwWkajL/KnKTGQ5gkBnYdZZ/tdtpNnQyyRjpA==",
"securityStamp": "4146b78a-8710-4951-90c9-da17af4e0d95",
"concurrencyStamp": "245bdd70-8d46-4e01-a512-2bb124fac42e",
"phoneNumber": null,
"phoneNumberConfirmed": false,
"twoFactorEnabled": false,
"lockoutEnd": null,
"lockoutEnabled": true,
"accessFailedCount": 0,
"roles": [],
"claims": [],
"logins": []
},
{
"firstName": "Client1",
"lastName": "1",
"residentialAddress": null,
"residentialSuburb": null,
"residentialPostCode": null,
"residentialCity": null,
"residentialstateTerritory": "NULL",
"postalAddress": null,
"postalSuburb": null,
"postalPostCode": null,
"postalCity": null,
"postalstateTerritory": "NULL",
"lastSync": "0001-01-01T00:00:00",
"accountCreated": "0001-01-01T00:00:00",
"lastVisited": "0001-01-01T00:00:00",
"client": null,
"clientID": null,
"id": "3466054a-42b5-4185-a677-4bf110dea420",
"userName": "Client1",
"normalizedUserName": "CLIENT1",
"email": null,
"normalizedEmail": null,
"emailConfirmed": true,
"passwordHash": "AQAAAAEAACcQAAAAELWrulfO5YQudMggGpvXPos54Faie7PxOac1/Yjy9PjY4PuSpb6Kpqfn85a4ABbVyg==",
"securityStamp": "47370050-772b-4365-8238-ebacebeea802",
"concurrencyStamp": "c072bf2e-9d21-4c66-95da-552fa0af50ca",
"phoneNumber": null,
"phoneNumberConfirmed": false,
"twoFactorEnabled": false,
"lockoutEnd": null,
"lockoutEnabled": true,
"accessFailedCount": 0,
"roles": [],
"claims": [],
"logins": []
},
{
"firstName": "Client0",
"lastName": "0",
"residentialAddress": null,
"residentialSuburb": null,
"residentialPostCode": null,
"residentialCity": null,
"residentialstateTerritory": "NULL",
"postalAddress": null,
"postalSuburb": null,
"postalPostCode": null,
"postalCity": null,
"postalstateTerritory": "NULL",
"lastSync": "0001-01-01T00:00:00",
"accountCreated": "0001-01-01T00:00:00",
"lastVisited": "2017-05-09T21:53:42.5080226",
"client": null,
"clientID": null,
"id": "a504e831-9524-480e-b5a0-745891da65b4",
"userName": "Client0",
"normalizedUserName": "CLIENT0",
"email": "fake#fake.com",
"normalizedEmail": "FAKE#FAKE.COM",
"emailConfirmed": true,
"passwordHash": "AQAAAAEAACcQAAAAEOvIdZDsXnYt+ToSYaKXmsnNSrfgwjy/Or4vM4pMo5gx45YFrxiZAig9a4ZEatg9KA==",
"securityStamp": "a4dcce55-660e-4d06-b2ed-ac065b6c0552",
"concurrencyStamp": "0b4759b5-e0a5-4a08-a3af-595360f8e30b",
"phoneNumber": null,
"phoneNumberConfirmed": false,
"twoFactorEnabled": false,
"lockoutEnd": "2017-05-02T01:55:03.7282498+00:00",
"lockoutEnabled": true,
"accessFailedCount": 0,
"roles": [],
"claims": [],
"logins": []
}
]
However, I only want a few of fields to be sent through the API like name and email just to protect user data.
{
"firstName": "Client2",
"lastName": "2",
"id": "2075c598-5bc3-4f74-a843-ac41e4d0bc36",
"userName": "Client2",
"normalizedUserName": "CLIENT2",
"email": null,
"normalizedEmail": null,
"phoneNumber": null,
},
How should I go about this?
How about just selecting the values from the list as an anonymous object
return Json(listErrorMsg(Clients.Select(a=> new {
firstName = a.firstName,
lastName = a.lastName,
id = a.id,
userName = a.userName,
normalizedUserName = a.normalizedUserName,
email = a.email,
normalizedEmail = a.normalizedEmail,
phoneNumber = a.phoneNumber
}));
I am using the LiveConnect sdk to get some user info.
After doing whatever is necessary for that, this is the result I'm getting:
{
"id": "123456789",
"name": "a b",
"first_name": "a",
"last_name": "b",
"link": "https://profile.live.com/",
"work": [],
"gender": null,
"emails": {
"preferred": "a#live.com",
"account": "a#live.com",
"personal": null,
"business": null
},
"addresses": {
"personal": {
"street": null,
"street_2": null,
"city": null,
"state": null,
"postal_code": null,
"region": null
},
"business": {
"street": null,
"street_2": null,
"city": null,
"state": null,
"postal_code": null,
"region": null
}
},
"locale": "en_US",
"updated_time": "2013-10-10T08:41:14+0000"
}
I need to get the "account" inside "emails".
First, when I got this string I did the following:
public Dictionary<string, object> userData = new Dictionary<string, object>();
userData = deserializeJsonObject(<the string above>);
private Dictionary<string, object> deserializeJsonObject(string json)
{
var jss = new JavaScriptSerializer();
var d = jss.Deserialize<Dictionary<string, object>>(json);
return d;
}
Now, in order to get the account email, I was going to do something like:
string email = userData["emails"]["account"];
but since this is a string, object dictionary, I get an error that it's not possible because userData["emails"] is an object.
How can I get the data?
do you had tried to make a cast?
for example:
(userData["emails"] as Dictionary<string,object>)["account"]
or:
((Dictionary<string,object>)userData["emails"])["account"]