Categories
Mastering Development

How to convert this json into string and get value of the ‘id’ property

I want to return only course id within jsonList.but My code is not working. My json output: “{\”courses\”:[{\”id\”:5,\”fullname\”:\”Course temp\”,\”displayname\”:\”Course temp\”,\”shortname\”:\”ct\”,\”categoryid\”:17,\”categoryname\”:\”Course templates\”,\”sortorder\”:40002,\”summary\”:\”\”,\”summaryformat\”:1,\”summaryfiles\”:[],\”overviewfiles\”:[],\”contacts\”:[],\”enrollmentmethods\”:[\”manual\”],\”idnumber\”:\”\”,\”format\”:\”topics\”,\”showgrades\”:1,\”newsitems\”:5,\”startdate\”:20120160,\”enddate\”:20120160,\”maxbytes\”:0,\”showreports\”:0,\”visible\”:1,\”groupmode\”:0,\”groupmodeforce\”:0,\”defaultgroupingid\”:0,\”enablecompletion\”:1,\”completionnotify\”:0,\”lang\”:\”\”,\”theme\”:\”\”,\”marker\”:0,\”legacyfiles\”:0,\”calendartype\”:\”\”,\”timecreated\”:1583825606,\”timemodified\”:1583910617,\”requested\”:0,\”cacherev\”:1583913808,\”filters\”:[{\”filter\”:\”displayh5p\”,\”localstate\”:0,\”inheritedstate\”:1},{\”filter\”:\”mathjaxloader\”,\”localstate\”:0,\”inheritedstate\”:1},{\”filter\”:\”activitynames\”,\”localstate\”:0,\”inheritedstate\”:1},{\”filter\”:\”mediaplugin\”,\”localstate\”:0,\”inheritedstate\”:1}],\”courseformatoptions\”:[{\”name\”:\”hiddensections\”,\”value\”:0},{\”name\”:\”coursedisplay\”,\”value\”:0}]}],\”warnings\”:[]}” My code:(I want to return only id) public int GetCourseDetails(Course course) { string URI = “http://localhost/Moodle/webservice/rest/server.php”; using (WebClient wc = new WebClient()) { wc.QueryString.Add(“wstoken”, “49345fa96c58118326b874bxxxxx”); wc.QueryString.Add(“wsfunction”, “core_course_get_courses_by_field”); wc.QueryString.Add(“moodlewsrestformat”, “json”); wc.QueryString.Add(“field”, “shortname”); wc.QueryString.Add(“value”,course.shortname); var response_data […]