- Get link
- X
- Other Apps
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.IO;
using System.Net;
//{
// "Code": 100,
// "Message": "OK",
// "Data": {
// "Index": 1,
// "YourClass": [
// {
// "id": 1,
// "nome": "agni"
// },
// {
// "id": 2,
// "nome": "jose"
// },
// {
// "id": 3,
// "nome": "marco"
// }
// ]
// }
//}
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string json = get_web_content("https://api.myjson.com/bins/vkjra");
dynamic array = JsonConvert.DeserializeObject(json);
dynamic Data = array.Data;
dynamic mList = Data.YourClass;
Console.WriteLine("");
Console.WriteLine("Lista de XXX");
Console.WriteLine("");
foreach (var item in mList)
{
Console.WriteLine("id: " + item["id"] );
Console.WriteLine("nome: " + item["nome"]);
Console.WriteLine("");
}
Console.ReadKey();
}
static string get_web_content(string url)
{
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();
response.Close();
return output;
}
}
public class YourClass
{
public int id;
public string nome;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.IO;
using System.Net;
//{
// "Code": 100,
// "Message": "OK",
// "Data": {
// "Index": 1,
// "YourClass": [
// {
// "id": 1,
// "nome": "agni"
// },
// {
// "id": 2,
// "nome": "jose"
// },
// {
// "id": 3,
// "nome": "marco"
// }
// ]
// }
//}
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string json = get_web_content("https://api.myjson.com/bins/vkjra");
dynamic array = JsonConvert.DeserializeObject(json);
dynamic Data = array.Data;
dynamic mList = Data.YourClass;
Console.WriteLine("");
Console.WriteLine("Lista de XXX");
Console.WriteLine("");
foreach (var item in mList)
{
Console.WriteLine("id: " + item["id"] );
Console.WriteLine("nome: " + item["nome"]);
Console.WriteLine("");
}
Console.ReadKey();
}
static string get_web_content(string url)
{
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string output = reader.ReadToEnd();
response.Close();
return output;
}
}
public class YourClass
{
public int id;
public string nome;
}
}
- Get link
- X
- Other Apps
Comments