"google": {
"regions": {
"937": {
"code": "Russia",
"countryCode": "ru",
"name": "Россия",
"id": 937,
"domain": {
"code": ".ru",
"name": "Росийская Федерация",
"id": 175
}
},
"979": {
"code": "Bryansk,Bryansk Oblast,Russia",
"countryCode": "ru",
"name": "Брянск",
"id": 979,
"domain": {
"code": ".ru",
"name": "Росийская Федерация",
"id": 175
}
}
},
"name": "Google"
},
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace JsonTest
{
public class Deserialized
{
public class Region
{
public class Domain
{
public string code { get; set; }
public string name { get; set; }
public int id { get; set; }
}
public string code { get; set; }
public string countryCode { get; set; }
public string name { get; set; }
public int id { get; set; }
public Domain domain { get; set; }
}
public Dictionary<int, Region> regions { get; set; }
}
class Program
{
static void Main(string[] args)
{
string json = @"{
""regions"": {
""937"": {
""code"": ""Russia"",
""countryCode"": ""ru"",
""name"": ""Россия"",
""id"": 937,
""domain"": {
""code"": "".ru"",
""name"": ""Росийская Федерация"",
""id"": 175
}
},
""979"": {
""code"": ""Bryansk,Bryansk Oblast,Russia"",
""countryCode"": ""ru"",
""name"": ""Брянск"",
""id"": 979,
""domain"": {
""code"": "".ru"",
""name"": ""Росийская Федерация"",
""id"": 175
}
}
}
}";
Deserialized data = JsonConvert.DeserializeObject<Deserialized>(json);
}
}
}
public static class OrderBasketTypeAdapter implements JsonDeserializer<OrderDto.Basket> {
@Override
public OrderDto.Basket deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
Set<Map.Entry<String, JsonElement>> entries = json.getAsJsonObject().entrySet();
OrderDto.Basket result = new OrderDto.Basket();
for (Map.Entry<String, JsonElement> entry : entries) {
OrderDto.Basket.BasketItemDto item = context.deserialize(entry.getValue(), OrderDto.Basket.BasketItemDto.class);
result.items.add(item);
}
return result;
}
}