When using JsonLayout - attribute with index 5 contains incorrect layout, is it bug or feature or I have incorrect settings? - c#

When using JsonLayout - attribute with index 5 contains incorrect layout. (Check screenshot attribute[5]. Layout is JsonLayout instead of "${aspnet-request-url}")
enter image description here
Config:
"elastic": {
"includeAllProperties": false,
"index": "plarium.rocks.artem.8-${date:format=yyyy.MM}",
"layout": {
"Attributes": [
{
"layout": "${date:format=o}",
"name": "time"
},
{
"layout": "${level:upperCase=true}",
"name": "level"
},
{
"name": "logger",
"layout": "${logger}"
},
{
"layout": "${message:raw=true}",
"name": "log_message"
},
{
"layout": "${exception}",
"name": "exception"
},
{
"layout": "${aspnet-request-url}",
"name": "empty-layout"
},
{
"layout": "${aspnet-request-url}",
"name": "request-url"
},
{
"layout": "${aspnet-request-method}",
"name": "request-method"
},
{
"layout": "${aspnet-user-identity}",
"name": "request-user"
},
{
"layout": "${when:when='${level}'!='ERROR':inner=restricted:else=${aspnet-request-posted-body}}",
"name": "request-body-payload"
},
{
"layout": "${aspnet-request-ip}",
"name": "request-remote-ip"
},
{
"layout": "${aspnet-mvc-controller}",
"name": "controller"
},
{
"layout": "${aspnet-request-duration}",
"name": "request-duration"
},
{
"name": "properties",
"encode": false,
"layout": {
"type": "JsonLayout",
"includeallproperties": false
}
}
],
"type": "JsonLayout"
},
"password": "",
"requireAuth": true,
"type": "ElasticSearch",
"uri": "",
"username": "",
"enableJsonLayout": true
},
References in the project: enter image description here
Tried setting up the NLog target, but it's not set up correctly.

Related

How to validate Json With schema C#

I am trying to validate JSON (API response) with a JSON schema with
string data = File.ReadAllText(#"C:\Users\Aman.Sharma\Source\Repos\Validator\Validator\testData.json");
string schema = File.ReadAllText(#"C:\Users\Aman.Sharma\Source\Repos\Validator\Validator\V2JsonSchema.json");
var model = JObject.Parse(data);
var json_schema = JSchema.Parse(schema);
bool valid = model.IsValid(json_schema, out IList<string> messages);
But the problem just throws an error with the first occurrence of error and skips the other part.
Is there any way to compare the whole JSON with schema and throw errors for each record?
Also this method If I change the schema always pass the JSON.
Sample Data
{
"id": "e1110047-b606-4fb3-84c6-28f7d5456e11",
"accountInactiveDate": "0001-01-01T00:00:00Z",
"accountOpenDate": "0001-01-01T00:00:00Z",
"accountTypeIds": [ 4000 ],
"address": {
"city": "vVjEKwUP",
"addressTypeId": 1000,
"countryISOCode": "GBR",
"street1": "xTMksdLL",
"zipCode": "12345"
},
"annualRevenue": 0.0,
"email": {
"emailTypeId": 1000,
"email": "zvvzwsdv#yopmail.com"
},
"homeLocationNumber": "316",
"industryTypeId": 0,
"isDeleted": false,
"name": "AccounttxecJizQ",
"parentAccountId": "00000000-0000-0000-0000-000000000000",
"phone": {
"phoneTypeId": 1000,
"number": "+44 123456"
},
"productsTypeIds": [ 3000 ],
"timeStamp": "\"2e001932-0000-0d00-0000-63315d8e0000\"",
"links": [
{
"href": "https://api-test.QA.cloud/companies/api/v2/accounts/e1110047-b606-4fb3-84c6-28f7d5456e11",
"rel": "Self"
}
],
"isBlocked": false,
"isComplete": true,
"createDate": "2022-09-26T08:06:38.2263447Z",
"systemCaller": "qa-user2-automationtests",
"originSystemCaller": "qa-user2-automationtests",
"originCreateDate": "2022-09-26T08:06:38.2263447Z"
}
Schema
{
"type": "object",
"properties": {
"searchMode": {
"enum": [
"Any",
"All"
],
"type": "string"
},
"queryType": {
"enum": [
"Simple",
"Full"
],
"type": "string"
},
"select": {
"type": "array",
"items": {
"type": "string"
}
},
"searchFields": {
"type": "array",
"items": {
"type": "string"
}
},
"orderBy": {
"type": "array",
"items": {
"type": "string"
}
},
"highlightPreTag": {
"type": "string"
},
"highlightPostTag": {
"type": "string"
},
"highlightFields": {
"type": "array",
"items": {
"type": "string"
}
},
"filter": {
"type": "string"
},
"facets": {
"type": "array",
"items": {
"type": "string"
}
},
"scoringProfile": {
"type": "string"
},
"scoringParameters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"values": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"page": {
"format": "int32",
"type": "integer"
},
"pageSize": {
"format": "int32",
"type": "integer"
},
"includeTotalResultCount": {
"type": "boolean"
}
}
}
I had similar errors with such approach.
Try add .Replace("\r", "").Replace("\n", "") at the end of code that reads data from files.
If it works - replace with less rude approach of ignoring of \r and \n.

Find values in dynamic JSON results

I am looking for a script to find the value of $6383.12 for Accounts Receivable (A/R) in this code. There are several values I want to be able to find but I can't seem to figure out how to structure my code to find the values I need.
I have spent time looking through and testing various versions of arrays, ILIst<> and other suggestions but I can't seem to get the final result I am looking for. I can find a single value (for example "Savings") but I don't know how to get the $800 value.
The script I am using is:
var root = JToken.Parse(data);
IList<JToken> t = root.SelectTokens("$...ColData[?(#.value == 'Accounts Receivable (A/R)')]").ToList();
foreach (var item in t)
{
Response.Write(item.ToString() + "<br/><br/>");
}
This gives me the Accounts Receivable (A/R) value but not the dollar value associated with it.
Here is the JSON result I am trying to parse through:
{
"Header": {
"ReportName": "BalanceSheet",
"Option": [
{
"Name": "AccountingStandard",
"Value": "GAAP"
},
{
"Name": "NoReportData",
"Value": "false"
}
],
"DateMacro": "this calendar year-to-date",
"ReportBasis": "Accrual",
"StartPeriod": "2016-01-01",
"Currency": "USD",
"EndPeriod": "2016-10-31",
"Time": "2016-10-31T09:42:21-07:00",
"SummarizeColumnsBy": "Total"
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "ASSETS"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Current Assets"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Bank Accounts"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "35",
"value": "Checking"
},
{
"value": "1350.55"
}
],
"type": "Data"
},
{
"ColData": [
{
"id": "36",
"value": "Savings"
},
{
"value": "800.00"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "BankAccounts",
"Summary": {
"ColData": [
{
"value": "Total Bank Accounts"
},
{
"value": "2150.55"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Accounts Receivable"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "84",
"value": "Accounts Receivable (A/R)"
},
{
"value": "6383.12"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "AR",
"Summary": {
"ColData": [
{
"value": "Total Accounts Receivable"
},
{
"value": "6383.12"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Other current assets"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "81",
"value": "Inventory Asset"
},
{
"value": "596.25"
}
],
"type": "Data"
},
{
"ColData": [
{
"id": "4",
"value": "Undeposited Funds"
},
{
"value": "2117.52"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "OtherCurrentAssets",
"Summary": {
"ColData": [
{
"value": "Total Other current assets"
},
{
"value": "2713.77"
}
]
}
}
]
},
"type": "Section",
"group": "CurrentAssets",
"Summary": {
"ColData": [
{
"value": "Total Current Assets"
},
{
"value": "11247.44"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Fixed Assets"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"id": "37",
"value": "Truck"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "38",
"value": "Original Cost"
},
{
"value": "13495.00"
}
],
"type": "Data"
}
]
},
"type": "Section",
"Summary": {
"ColData": [
{
"value": "Total Truck"
},
{
"value": "13495.00"
}
]
}
}
]
},
"type": "Section",
"group": "FixedAssets",
"Summary": {
"ColData": [
{
"value": "Total Fixed Assets"
},
{
"value": "13495.00"
}
]
}
}
]
},
"type": "Section",
"group": "TotalAssets",
"Summary": {
"ColData": [
{
"value": "TOTAL ASSETS"
},
{
"value": "24742.44"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "LIABILITIES AND EQUITY"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Liabilities"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Current Liabilities"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"Header": {
"ColData": [
{
"value": "Accounts Payable"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "33",
"value": "Accounts Payable (A/P)"
},
{
"value": "1984.17"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "AP",
"Summary": {
"ColData": [
{
"value": "Total Accounts Payable"
},
{
"value": "1984.17"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Credit Cards"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "41",
"value": "Mastercard"
},
{
"value": "157.72"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "CreditCards",
"Summary": {
"ColData": [
{
"value": "Total Credit Cards"
},
{
"value": "157.72"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Other Current Liabilities"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "89",
"value": "Arizona Dept. of Revenue Payable"
},
{
"value": "4.55"
}
],
"type": "Data"
},
{
"ColData": [
{
"id": "90",
"value": "Board of Equalization Payable"
},
{
"value": "401.98"
}
],
"type": "Data"
},
{
"ColData": [
{
"id": "43",
"value": "Loan Payable"
},
{
"value": "4000.00"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "OtherCurrentLiabilities",
"Summary": {
"ColData": [
{
"value": "Total Other Current Liabilities"
},
{
"value": "4406.53"
}
]
}
}
]
},
"type": "Section",
"group": "CurrentLiabilities",
"Summary": {
"ColData": [
{
"value": "Total Current Liabilities"
},
{
"value": "6548.42"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Long-Term Liabilities"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "44",
"value": "Notes Payable"
},
{
"value": "25000.00"
}
],
"type": "Data"
}
]
},
"type": "Section",
"group": "LongTermLiabilities",
"Summary": {
"ColData": [
{
"value": "Total Long-Term Liabilities"
},
{
"value": "25000.00"
}
]
}
}
]
},
"type": "Section",
"group": "Liabilities",
"Summary": {
"ColData": [
{
"value": "Total Liabilities"
},
{
"value": "31548.42"
}
]
}
},
{
"Header": {
"ColData": [
{
"value": "Equity"
},
{
"value": ""
}
]
},
"Rows": {
"Row": [
{
"ColData": [
{
"id": "34",
"value": "Opening Balance Equity"
},
{
"value": "-9337.50"
}
],
"type": "Data"
},
{
"ColData": [
{
"id": "2",
"value": "Retained Earnings"
},
{
"value": "91.25"
}
],
"type": "Data"
},
{
"ColData": [
{
"value": "Net Income"
},
{
"value": "2440.27"
}
],
"type": "Data",
"group": "NetIncome"
}
]
},
"type": "Section",
"group": "Equity",
"Summary": {
"ColData": [
{
"value": "Total Equity"
},
{
"value": "-6805.98"
}
]
}
}
]
},
"type": "Section",
"group": "TotalLiabilitiesAndEquity",
"Summary": {
"ColData": [
{
"value": "TOTAL LIABILITIES AND EQUITY"
},
{
"value": "24742.44"
}
]
}
}
]
},
"Columns": {
"Column": [
{
"ColType": "Account",
"ColTitle": "",
"MetaData": [
{
"Name": "ColKey",
"Value": "account"
}
]
},
{
"ColType": "Money",
"ColTitle": "Total",
"MetaData": [
{
"Name": "ColKey",
"Value": "total"
}
]
}
]
}
}
You can try this,
var json = File.ReadAllText("json1.json");
var jToken = JToken.Parse(json);
var reader = jToken.CreateReader();
while (reader.Read())
{
var value = reader.Value;
if (value != null && value.ToString() == "Accounts Receivable (A/R)")
{
var test = jToken.SelectToken(reader.Path.Replace("[0].value", "[1].value"));
}
}
If it's not doable to write json path which selects proper tokens you could try using Parent property and Children method.
foreach (var item in t)
{
var valueToken = item.Parent.Children().ElementAt(1);
Response.Write(valueToken.ToString() + "<br/><br/>");
}

how should i get the json references inline rather than getting it references - should NOT have additional properties additionalProperty: definitions

I am new to JsonSchema, I am trying to generate swagger(3.0) JSON. I am using NJsonSchema.
It has successfully generated the JSON schema for models. The only problem is that the JSON has references to the complex type. I tried the generated JSON in http://editor.swagger.io/ and the UI is generated fine, but I have a lot of structural error.
Structural error at paths./xyz/asd/abc/.schema
should NOT have additional properties
additionalProperty: definitions
following is the sample JSON which can be tested on the above link.
{
"openapi": "3.0.1",
"info": {
"title": "SomeTitle",
"description": "someDescription",
"version": "v1"
},
"paths": {
"/Device": {
"get": {
"summary": "someSummary",
"tags": [
"Device"
],
"parameters": [
{
"name": "id",
"in": "query",
"description": "deviceId",
"required": true,
"schema": {
"type": "string",
"nullable": false
}
}
],
"responses": {
"200": {
"description": "Success.",
"content": {
"application/json": {
"schema": {
"title": "SomeTitleAgain",
"type": "object",
"additionalProperties": false,
"required": [
"id"
],
"properties": {
"id": {
"type": "string"
},
"udiCarrier": {
"$ref": "#/paths/~1Device/get/responses/200/content/application~1json/schema/definitions/ListOfUdiCarrierComponent"
}
},
"definitions": {
"ListOfUdiCarrierComponent": {
"type": "array",
"items": {
"$ref": "#/paths/~1Device/get/responses/200/content/application~1json/schema/definitions/UdiCarrierComponent"
}
},
"UdiCarrierComponent": {
"type": "object",
"additionalProperties": false,
"properties": {
"carrierHRF": {
"type": "string"
}}}}}}}}}}}},
"components": { }
}
I don't think NJsonSchema gives a way to get rid of schema reference handling.
So JSON generated always has these references.
Is there any way to process this schema and get the references inline?
I also looked for NewtonsoftJson's IReferenceResolver examples on the internet but could not get a clear picture of how can I use it.
Thanks in Advance.
I have corrected you JSON file with the correct way to use schema and $ref attribute:
{
"openapi": "3.0.1",
"info": {
"title": "SomeTitle",
"description": "someDescription",
"version": "v1"
},
"paths": {
"/Device": {
"get": {
"summary": "someSummary",
"tags": [
"Device"
],
"parameters": [
{
"name": "id",
"in": "query",
"description": "deviceId",
"required": true,
"schema": {
"type": "string",
"nullable": false
}
}
],
"responses": {
"200": {
"description": "Success.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ListOfUdiCarrierComponent"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"ListOfUdiCarrierComponent": {
"title": "SomeTitleAgain",
"type": "object",
"additionalProperties": false,
"required": [
"id"
],
"properties": {
"id": {
"type": "string"
},
"udiCarrier": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UdiCarrierComponent"
}
}
}
},
"UdiCarrierComponent": {
"type": "object",
"additionalProperties": false,
"properties": {
"carrierHRF": {
"type": "string"
}
}
}
}
}
}

DialogFlow not triggering Event Intent when sending action via ASP.NET Webhook

I am building a .NET Webhook following this tutorial, dialogflow fulfillment with c and app engine.
Everything works fine except when I want to set up DailyUpdates with a RegisterUpdate Intent.
When the "setup_notification_update" intent calls the webhook I sendthis kind of JSON in response:
{
"fulfillmentText": "Notifica programmata",
"fulfillmentMessages": [
{
"card": {
"title": "Notifica programmata",
"subtitle": "Notifica programmata con successo",
"imageUri": "https://assistant.google.com/static/images/molecule/Molecule-Formation-stop.png",
"buttons": [
{
"text": "Valutami",
"postback": "https://macoev.com/"
}
]
}
}
],
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Questa รจ la risposta di avvenuto successo per la programmazione della notifica"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.REGISTER_UPDATE",
"data": {
"#type": "type.googleapis.com/google.actions.v2.RegisterUpdateValueSpec",
"intent": "get_stats_notification",
"arguments": [
{
"name": "category",
"textValue": "Daily_lowest_temperature"
}
],
"triggerContext": {
"timeContext": {
"frequency": "DAILY"
}
}
}
}
}
}
}
The problem is that the intent that has REGISTER_UPDATE as its event does not get triggered, resulting in the notification not being scheduled.
This is the response that I set when that event get triggered:
{
"responseId": "",
"queryResult": {
"queryText": "",
"action": "",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentText": "",
"fulfillmentMessages": [],
"outputContexts": [],
"intent": {
"name": "finish_update_setup",
"displayName": "finish_update_setup"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": ""
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
},
"inputs": [
{
"rawInputs": [],
"intent": "",
"arguments": [
{
"name": "REGISTER_UPDATE",
"extension": {
"#type": "type.googleapis.com/google.actions.v2.RegisterUpdateValue",
"status": "OK"
}
},
{
"name": "text",
"rawText": "04:10pm",
"textValue": "04:10pm"
}
]
}
],
"user": {},
"conversation": {},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
}
]
}
},
"session": ""
}
Any idea why? Any help will be appreciated. Thanks in advance.

Gmail contacts/ deserialize json object containing emails

I wanted to get gmail contacts(email contacts actually), so I registered on google developer console and got the credentials, and using access token got the contacts. With scopes:
https://www.google.com/m8/feeds/ + https://www.googleapis.com/auth/contacts.readonly
and request uri as :
https://www.google.com/m8/feeds/contacts/default/full?alt=json
which gave me this json result:
{
"version": "1.0",
"encoding": "UTF-8",
"feed": {
"xmlns": "http://www.w3.org/2005/Atom",
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/",
"xmlns$batch": "http://schemas.google.com/gdata/batch",
"xmlns$gd": "http://schemas.google.com/g/2005",
"xmlns$gContact": "http://schemas.google.com/contact/2008",
"id": {
"$t": "xxx#test.ai"
},
"updated": {
"$t": "2017-03-17T16:00:05.743Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"type": "text",
"$t": "xxx's Contacts"
},
"link": [
{
"rel": "alternate",
"type": "text/html",
"href": "http://www.google.com/"
},
{
"rel": "http://schemas.google.com/g/2005#feed",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full"
},
{
"rel": "http://schemas.google.com/g/2005#post",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full"
},
{
"rel": "http://schemas.google.com/g/2005#batch",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/batch"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full?alt=json&max-results=25"
},
{
"rel": "next",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full?alt=json&start-index=26&max-results=25"
}
],
"author": [
{
"name": {
"$t": "xxx"
},
"email": {
"$t": "xxx#test.ai"
}
}
],
"generator": {
"version": "1.0",
"uri": "http://www.google.com/m8/feeds",
"$t": "Contacts"
},
"openSearch$totalResults": {
"$t": "32"
},
"openSearch$startIndex": {
"$t": "1"
},
"openSearch$itemsPerPage": {
"$t": "25"
},
"entry": [
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/ca1e0840ced5eb5"
},
"updated": {
"$t": "2017-03-13T10:27:43.365Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"type": "text",
"$t": "Adam aaa"
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/ca1e0840ced5eb5/1B2M2Y8AsgTpgAmY7PhCfg"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/ca1e0840ced5eb5"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/ca1e0840ced5eb5/1489400863365001"
}
],
"gd$email": [
{
"rel": "http://schemas.google.com/g/2005#other",
"address": "adam#test.ai",
"primary": "true"
}
]
},
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/d06991a8a601600"
},
"updated": {
"$t": "2017-03-13T10:27:43.365Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"type": "text",
"$t": "Bailey Bob"
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/d06991a8a601600/1B2M2Y8AsgTpgAmY7PhCfg"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/d06991a8a601600"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/d06991a8a601600/1489400863365001"
}
],
"gd$email": [
{
"rel": "http://schemas.google.com/g/2005#other",
"address": "bailey#test.ai",
"primary": "true"
}
]
},
{
"id": {
"$t": "http://www.google.com/m8/feeds/contacts/xxx%40test.ai/base/e33f110891b26a2"
},
"updated": {
"$t": "2017-03-13T10:27:43.365Z"
},
"category": [
{
"scheme": "http://schemas.google.com/g/2005#kind",
"term": "http://schemas.google.com/contact/2008#contact"
}
],
"title": {
"type": "text",
"$t": "cathy Wales"
},
"link": [
{
"rel": "http://schemas.google.com/contacts/2008/rel#edit-photo",
"type": "image/*",
"href": "https://www.google.com/m8/feeds/photos/media/xxx%40test.ai/e33f110891b26a2/1B2M2Y8AsgTpgAmY7PhCfg"
},
{
"rel": "self",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/e33f110891b26a2"
},
{
"rel": "edit",
"type": "application/atom+xml",
"href": "https://www.google.com/m8/feeds/contacts/xxx%40test.ai/full/e33f110891b26a2/1489400863365001"
}
],
"gd$email": [
{
"rel": "http://schemas.google.com/g/2005#other",
"address": "cathy#test.ai",
"primary": "true"
}
]
}
]
}
}
Either I need a better way to get the email contacts out of gmail or I need a way to deserialize this json to class, I tried to deserialize by converting this json to C# but proved unsuccessful.
Let me know what can be done.
Resolved my issue, at times when comes with instances like '$t' or something similar having '$' in it, which when converted into C# class results in invalid name. To resolve that, add dll reference 'Newtonsoft.Json' and create a class with using namespace as 'using Newtonsoft.Json' and in each property where name becomes invalid like below;
public string __invalid_name__$t { get; set; }
Add Json property attribute like below and change the name as per your liking:
[JsonProperty("$t")]
public string NameOfMyChoosing { get; set; }

Categories

Resources