CSharp · Console
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
public class Program
{
public static void Main()
{
string input = @"{
""predictions"": [
{
""description"": ""Frankfurt am Main, Deutschland"",
""place_id"": ""ChIJxZZwR28JvUcRAMawKVBDIgQ"",
},
{
""description"": ""Frankfurt (Oder), Deutschland"",
""place_id"": ""ChIJb_u1AiqYB0cRwDteW0YgIQQ"",
},
{
""description"": ""Frankfurt Hahn Flughafen (HHN), Lautzenhausen, Deutschland"",
""place_id"": ""ChIJX3W0JgQYvkcRWBxGlm6csj0"",
}
],
""status"": ""OK""
}";
//Console.WriteLine(input);
var objs = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponseWrapper>(input);
//FiddleHelper.Dump(objs);
var output = Newtonsoft.Json.JsonConvert.SerializeObject(objs, new Newtonsoft.Json.JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore });
Console.WriteLine(output);
}
public class ResponseWrapper
{
[JsonProperty("success")]
public bool Success { get;set; }
[JsonProperty("message")]
public string Message { get;set; }
[Obsolete("This field should not be used anymore, please use Message instead", true)]
public string Status
{
set
{
Message = value;
Success = value.Equals("OK", StringComparison.OrdinalIgnoreCase);
}
}
[JsonProperty("data")]
public Prediction[] Data { get;set; }
[Obsolete("This field should not be used anymore, please use Data instead", true)]
public Prediction[] Predictions
{
set { Data = value; }
}
}
public class Prediction
{
public string description { get; set; }
public string place_id { get; set; }
}
}