I'm going to parse the JSON data to class using C# and Newtonsoft.Json. But the JSON data is a little bit different than usual. Here is the JSON data sample:
{
"ip_addresses": [
"192.168.1.1"
],
"ptr": {
"192.168.1.1": "www.example.com"
}
}
So the problem is the IP in ptr changes due to the IP in ip_addresses. I've successfully parsed ip_addresses data into the List. But I don't know how to do next with the List stored IP addresses.
class Server
{
public string hostname { get; set; }
public List<string> ip_addresses { get; set; }
public override string ToString()
{
string ip_set = string.Empty;
foreach (string ip in ip_addresses)
{
ip_set += string.Format("{0} ", ip);
}
return string.Format("{0} {1}\n", hostname, ip_set)
}
}
class Program
{
static void Main(string[] args)
{
//json data is from the web response
string responseContent = reader.ReadToEnd();
Server server = JsonConvert.DeserializeObject<Server>(responseContent);
Console.WriteLine(server);
Console.ReadKey();
}
}
Thanks a lot :D