In C #, I have 5-6 days and I wanted to try to use the api one site. I have deserialize JSON and here is the format
[ { "uid": 1476402, "first_name": "", "last_name": "", "domain": "sandrische", "online": 1, "user_id": 1476402 }, { "uid": 3813182, "first_name": "", "last_name": "", "domain": "id3813182", "online": 0, "user_id": 3813182 }, { "uid": 12789624, "first_name": "", "last_name": "", "domain": "id12789624", "online": 0, "user_id": 12789624 }]
there is a class
public class vkResponse
{
[JsonProperty(PropertyName = "uid")]
public int Id { get; set; }
[JsonProperty(PropertyName = "first_name")]
public string FirstName { get; set; }
[JsonProperty(PropertyName = "last_name")]
public string LastName { get; set; }
[JsonProperty(PropertyName = "photo_50")]
public Uri PhotoUri { get; set; }
[JsonProperty(PropertyName = "online")]
[JsonConverter(typeof(BoolConverter))]
public bool IsOnline { get; set; }
[JsonProperty(PropertyName = "lists")]
public List<int> Lists { get; set; }
}
public class BoolConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(((bool)value) ? 1 : 0);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
return reader.Value.ToString() == "1";
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(bool);
}
}
I want to get id
var req = new HttpRequest();
string resp = req.Get("https://api.vk.com/method/friends.get?user_ids=1&fields=domain&access_token=" + GetToken()).ToString();
JObject o = JObject.Parse(resp);
JArray array = (JArray)o["response"];
vkResponse v = JsonConvert.DeserializeObject<vkResponse>(array.First().ToString());
richTextBox1.Text = v.Id.ToString();
But I get only the first ID, how to get all ID?
I think that the problem in this array.First().ToString()
? Please help or give an example.