-2

I have string as shown below

"{\"id\":\"3b6f\",\"campaign_title\":\"\",\"type\":\"regular\",\"list_id\":\"aaeb6\",\"list_name\":\"FT-2\",\"subject_line\":\"Funtional Testing 2 Campaign\",\"emails_sent\":4,\"abuse_reports\":0,\"unsubscribed\":1,\"send_time\":\"2017-01-03T07:50:27+00:00\",\"bounces\":{\"hard_bounces\":0,\"soft_bounces\":0,\"syntax_errors\":0},\"forwards\":{\"forwards_count\":0,\"forwards_opens\":0},\"opens\":{\"opens_total\":2,\"unique_opens\":2,\"open_rate\":0.5,\"last_open\":\"2017-01-03T08:05:28+00:00\"},\"clicks\":{\"clicks_total\":0,\"unique_clicks\":0,\"unique_subscriber_clicks\":0,\"click_rate\":0,\"last_click\":\"\"},\"facebook_likes\":{\"recipient_likes\":0,,\"targetSchema\":\"https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Unsubscribed/CollectionResponse.json\"}]}"

I need to find values from this string. As an example {\"id\":\"3b6f\". I need 3b6f from this string. How can I get my required from this string?

huse.ckr
  • 530
  • 12
  • 39
  • 4
    Use a JSON parser. Ex: http://www.newtonsoft.com/json – 001 Jan 03 '17 at 14:21
  • 1
    It's JSON, except you have an extra comma in there that's going to cause it to fail parsing - `\"recipient_likes\":0,,\"targetSchema\"` – Jonesopolis Jan 03 '17 at 14:28
  • I got the answer for my question.Use Nuget manager to install Newtonsoft.Json and use it in your c# code var response = webClient.DownloadString(uri); dynamic a = JsonConvert.DeserializeObject(response); Console.WriteLine(a.id); Console.ReadLine(); – Abdul Wahab Jan 04 '17 at 07:08

1 Answers1

1

You could easily do it with JSon.net:

JObject.Parse(yourJson)["id"]

But your json is not valid, i've got error message:

Invalid property identifier character: ,. Path 'facebook_likes.recipient_likes', line 1, position 582.

you have an extra comma and you have closing array bracket without opening one. Valid json could be:

{\"id\":\"3b6f\",\"campaign_title\":\"\",\"type\":\"regular\",\"list_id\":\"aaeb6\",\"list_name\":\"FT-2\",\"subject_line\":\"Funtional Testing 2 Campaign\",\"emails_sent\":4,\"abuse_reports\":0,\"unsubscribed\":1,\"send_time\":\"2017-01-03T07:50:27+00:00\",\"bounces\":{\"hard_bounces\":0,\"soft_bounces\":0,\"syntax_errors\":0},\"forwards\":{\"forwards_count\":0,\"forwards_opens\":0},\"opens\":{\"opens_total\":2,\"unique_opens\":2,\"open_rate\":0.5,\"last_open\":\"2017-01-03T08:05:28+00:00\"},\"clicks\":{\"clicks_total\":0,\"unique_clicks\":0,\"unique_subscriber_clicks\":0,\"click_rate\":0,\"last_click\":\"\"},\"facebook_likes\":{\"recipient_likes\":0,\"targetSchema\":\"https://us14.api.mailchimp.com/schema/3.0/Definitions/Reports/Unsubscribed/CollectionResponse.json\"}}

Maksim Simkin
  • 9,561
  • 4
  • 36
  • 49