How to get those data and deserialize them into our object data ?
You can check out the following C# code :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Common; | |
using System.Net; | |
using System.IO; | |
using System.Web.Script.Serialization; | |
namespace JsonConsoleApplication | |
{ | |
class Program | |
{ | |
private const string apiUrl = "http://www.example.com"; | |
private const string loginname = "xxxx"; | |
private const string password = "****"; | |
static void Main(string[] args) | |
{ | |
WebClient webClient = new WebClient(); | |
string url = apiUrl; | |
webClient.Credentials = new System.Net.NetworkCredential(loginname,password); | |
var json = webClient.DownloadString(url); | |
JavaScriptSerializer parser = new JavaScriptSerializer(); | |
var info = parser.Deserialize<List<Track>>(json); | |
List<Track> listTrack = (List<Track>)info; | |
//note that List<Track> is an object, you can change it by yours | |
} | |
} | |
} |
For further knowledge about JSON, you can visit Mastering JSON
May it helps,
Thanks
No comments:
Post a Comment