web
You’re offline. This is a read only version of the page.
close
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,119 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

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    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);
    }
  • Community Member Profile Picture
    on at

    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

  • Verified answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi all

    I only write this and It will work for me

    responseStatus.emails[0].email_address

    Thank You

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans