Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to parse J Son response in c#

(1) ShareShare
ReportReport
Posted on by 12,081 Moderator

Hi all

I have this response.

{{
"emails": [
{
"campaign_id": "417fed3b6f",
"list_id": "aae9496eb6",
"email_id": "2ffaef1aff65c7602c8c2b29cf0d3444",
"email_address": "ilal@aw.com",
"activity": [],
"_links": [
{
"rel": "parent",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/CollectionResponse.json"
},
{
"rel": "self",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity/2ffaef1aff65c7602c8c2b29cf0d3444",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/Response.json"
},
{
"rel": "member",
"href": "https://us14.api.mailchimp.com/3.0/lists/aae9496eb6/members/2ffaef1aff65c7602c8c2b29cf0d3444",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
}
]
},
{
"campaign_id": "417fed3b6f",
"list_id": "aae9496eb6",
"email_id": "f0a64ba761c590d7a4c6be5f45476a8f",
"email_address": "ahab@aw.com",
"activity": [
{
"action": "open",
"timestamp": "2017-01-03T12:50:52+05:00",
"ip": "202.163.111.73"
},
{
"action": "open",
"timestamp": "2017-01-04T11:39:46+05:00",
"ip": "202.163.111.73"
},
{
"action": "open",
"timestamp": "2017-01-04T15:17:43+05:00",
"ip": "202.163.111.73"
},
{
"action": "open",
"timestamp": "2017-01-04T15:17:43+05:00",
"ip": "202.163.111.73"
}
],
"_links": [
{
"rel": "parent",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/CollectionResponse.json"
},
{
"rel": "self",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity/f0a64ba761c590d7a4c6be5f45476a8f",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/Response.json"
},
{
"rel": "member",
"href": "https://us14.api.mailchimp.com/3.0/lists/aae9496eb6/members/f0a64ba761c590d7a4c6be5f45476a8f",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
}
]
},
{
"campaign_id": "417fed3b6f",
"list_id": "aae9496eb6",
"email_id": "1d6c76b461ed68197f9e6bc609891b2d",
"email_address": "tahamal@aw.com",
"activity": [
{
"action": "open",
"timestamp": "2017-01-03T13:05:28+05:00",
"ip": "202.163.111.73"
},
{
"action": "open",
"timestamp": "2017-01-05T16:24:41+05:00",
"ip": "202.163.111.73"
}
],
"_links": [
{
"rel": "parent",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/CollectionResponse.json"
},
{
"rel": "self",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity/1d6c76b461ed68197f9e6bc609891b2d",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/Response.json"
},
{
"rel": "member",
"href": "https://us14.api.mailchimp.com/3.0/lists/aae9496eb6/members/1d6c76b461ed68197f9e6bc609891b2d",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
}
]
},
{
"campaign_id": "417fed3b6f",
"list_id": "aae9496eb6",
"email_id": "02e68671c4613b19d66779687197a43f",
"email_address": "if@aw.com",
"activity": [],
"_links": [
{
"rel": "parent",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/CollectionResponse.json"
},
{
"rel": "self",
"href": "https://us14.api.mailchimp.com/3.0/reports//email-activity/02e68671c4613b19d66779687197a43f",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/Response.json"
},
{
"rel": "member",
"href": "https://us14.api.mailchimp.com/3.0/lists/aae9496eb6/members/02e68671c4613b19d66779687197a43f",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
}
]
}
],
"campaign_id": "417fed3b6f",
"total_items": 4,
"_links": [
{
"rel": "parent",
"href": "https://us14.api.mailchimp.com/3.0/reports/417fed3b6f",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Response.json"
},
{
"rel": "self",
"href": "https://us14.api.mailchimp.com/3.0/reports/417fed3b6f/email-activity",
"method": "GET",
"targetSchema": "https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Email-Activity/CollectionResponse.json"
}
]
}}

I want to get email addresses from this response.

My code is this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json; // I use it for JsonConvert
using System.Net;// use for web client
using System.IO; // use for StreamReader


namespace GetCampaignInformationTest
{
class Program
{
static void Main(string[] args)
{
string dataCenter = "u4";
string apiKey = "aca886a92e5a";
string field = "delivery_status";
var json = JsonConvert.SerializeObject(field);
var uri = string.Format("https://{0}.api.mailchimp.com/3.0/reports/3b6f/email-activity", dataCenter);
try
{
using (var webClient = new WebClient())
{
webClient.Headers.Add("Accept", "application/json");
webClient.Headers.Add("Authorization", "apikey " + apiKey);
var response = webClient.DownloadString(uri);

dynamic responseStatus = JsonConvert.DeserializeObject(response);
Console.WriteLine("responseStatus.clicks.clicks_total:" + responseStatus.emails.email_address); //This is line is giving me error


Console.ReadLine();
}
}
catch (WebException we)
{
using (var sr = new StreamReader(we.Response.GetResponseStream()))
{
Console.WriteLine(sr.ReadToEnd());
Console.ReadLine();
}
}
}
}
}

How can I get email addresses with that response?

Thank You

*This post is locked for comments

  • Verified answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,081 Moderator on at
    RE: How to parse J Son response in c#

    Hi all

    I only write this and It will work for me

    responseStatus.emails[0].email_address

    Thank You

  • RE: How to parse J Son response in c#

    are you sure you can use dynamic for "responseStatus"?

    when I did something similar but for plugin code, I had to turn the response into an UTF8 string then deserialize into a Dictionary object.

    you code:

    var response = webClient.DownloadString(uri);

    dynamic responseStatus = JsonConvert.DeserializeObject(response);

    the code I used:

    string resultStr = Encoding.UTF8.GetString(result, 0, result.Length); //result from json

    var resobj = JsonConvert.DeserializeObject<Dictionary<String, Object>>(resultStr); //deserialize object

    hope this helps

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: How to parse J Son response in c#

    Hi Abdul Wahab,

    Add this namspace : using Newtonsoft.Json.Linq;

    Try the following code.

    function retrieveRecordsSynchronously() {
    var retrieveRecordsReq = new XMLHttpRequest();
    var ODataPath = Xrm.Page.context.getServerUrl() + “/XRMServices/2011/OrganizationData.svc/AccountSet”;
    retrieveRecordsReq.open(‘GET’, ODataPath, false);
    retrieveRecordsReq.setRequestHeader(“Accept”, “application/json”);
    retrieveRecordsReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8″);
    retrieveRecordsReq.send(null);
    var records = JSON.parse(retrieveRecordsReq.responseText).d;
    //Read the first account name
    alert(‘First Account Name is: ‘ + records.results[0].Name);
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans