,  , C#

 
 
 4.80/5:  :  - 5,   - 4.80
0 / 0 / 0
: 04.08.2015
: 111
1

json

31.01.2017, 14:03. 870. 8
( )

json:
JSON
1
{"response":[201,{"id":1096,"title":"I . . ѳ (.  . . )"},{"id":1135,"title":" (.  (. ))"},{"id":1140,"title":" .  - (.  . -)"},{"id":1153,"title":" (.  (. ))"},{"id":1231,"title":" (, )"},{"id":1282,"title":" .   (.  . .  ( . . . ))"},{"id":1656,"title":" (. ) (.  (. ))"},{"id":1686,"title":" (. )"},{"id":1892,"title":" ̳ ³ (. )"},{"id":2866,"title":" ( Ҳ) (. )"},{"id":2881,"title":" .   (.  . . )"},{"id":2984,"title":" . . .    (.   )"},{"id":3063,"title":" (. IJ, ) (.  (. ))"},{"id":3216,"title":""},{"id":3272,"title":"޲   (.   )"},{"id":3336,"title":" (. )"},{"id":3502,"title":" . . (.  . . )"},{"id":3750,"title":" . . . "},{"id":3814,"title":" () . "},{"id":3990,"title":""},{"id":4013,"title":" (. )"},{"id":4658,"title":""},{"id":5181,"title":"ʳ (. )"},{"id":5616,"title":" (. )"},{"id":6039,"title":""},{"id":6400,"title":" ()"},{"id":7020,"title":"  (.   (. ))"},{"id":7671,"title":" (. Ӳ) (.  (. ))"},{"id":7959,"title":"ʳ . .. - (.  () . . . -)"},{"id":8384,"title":" ()"},{"id":8496,"title":""},{"id":8915,"title":""},{"id":9426,"title":" "},{"id":9871,"title":""},{"id":10220,"title":" (. ) (.  (. ))"},{"id":10637,"title":"²Ҳ (.  (.   Ȼ))"},{"id":10973,"title":""},{"id":11608,"title":" . . "},{"id":11837,"title":"  (.  () )"},{"id":11886,"title":" (. I) (.  (. ))"},{"id":12610,"title":"  ()  "},{"id":12624,"title":"  . . .  (.   . . . )"},{"id":12752,"title":""},{"id":13061,"title":" (. ϲ) (.  (. ))"},{"id":13607,"title":""},{"id":15708,"title":" (. )"},{"id":16215,"title":" . . . "},{"id":16713,"title":" (. )"},{"id":16765,"title":" (. )"},{"id":16908,"title":""},{"id":17136,"title":""},{"id":17612,"title":"   "},{"id":17622,"title":" () (.  () )"},{"id":18115,"title":"IJ̳ . .  (.  . . )"},{"id":18346,"title":" (.  (. ))"},{"id":18594,"title":" "},{"id":18682,"title":" . .  (. ) (.  . .  (. ))"},{"id":18973,"title":""},{"id":19047,"title":" (. )"},{"id":19281,"title":" (. ʲ, ) (.  (. , ))"},{"id":19501,"title":" ( )"},{"id":19504,"title":"   "},{"id":20154,"title":" (.  (, ))"},{"id":20383,"title":"  "},{"id":21019,"title":" (. )"},{"id":21202,"title":""},{"id":21471,"title":" ()"},{"id":22250,"title":" (. )"},{"id":23088,"title":" () .  "},{"id":23174,"title":""},{"id":23387,"title":" ()"},{"id":23578,"title":" . ..  (.  . . . )"},{"id":23942,"title":" (, )"},{"id":24863,"title":" (. , ) (.  (. , ))"},{"id":25282,"title":" (, , )"},{"id":34004,"title":""},{"id":34970,"title":""},{"id":35599,"title":" . "},{"id":35643,"title":""},{"id":39199,"title":""},{"id":41226,"title":""},{"id":41679,"title":" (KSE)"},{"id":43042,"title":""},{"id":62644,"title":""},{"id":91571,"title":"   .  ( 1994 .)"},{"id":91934,"title":" ( 1990 .)"},{"id":93413,"title":" .   "},{"id":105328,"title":" "},{"id":126961,"title":" ()"},{"id":141734,"title":""},{"id":141808,"title":"  ( 2000 .)"},{"id":167678,"title":""},{"id":167838,"title":" ()   "},{"id":168167,"title":"   Ȼ"},{"id":168202,"title":" .  ()"},{"id":170274,"title":" "},{"id":170275,"title":" "},{"id":170282,"title":"-"},{"id":170397,"title":" "},{"id":176164,"title":"  . .  (.   . . )"}]}
. :
C#
1
2
3
4
5
6
7
8
9
public class RootObjectUnivercity
        {
            public List<Univercity> response { get; set; }
        }
public class Univercity
        {
            public int id { get; set; }
            public string title { get; set; }
        }
:
C#
1
RootObjectUnivercity rootUnivercity = (RootObjectUnivercity)new DataContractJsonSerializer(typeof(RootObjectUnivercity)).ReadObject(stream); //  stream  json  .
, - 201 json . - : " , count , , items. : id (integer) ; title (string) ." json.
0
? .
Similar
41792 / 34177 / 6122
: 12.04.2006
: 57,940
31.01.2017, 14:03
:

?
: class A { public void...

JSON JSON.NET?
, . . ...

[JSON.NET] Json ?
Json : { field1: { ...

Json - Cannot deserialize the current JSON array because the type requires a JSON object
: Cannot deserialize the current JSON object (e.g....

Json - Cannot deserialize the current JSON array because the type requires a JSON object
! , , : An unhandled exception...

8
Goal
513 / 415 / 140
: 31.10.2011
: 1,008
: 2
31.01.2017, 15:30 2
, ?

:
C#
1
2
3
//namespace Newtonsoft.Json
 
var rootObj = JsonConvert.DeserializeObject<RootObjectUnivercity>(string);
0
0 / 0 / 0
: 04.08.2015
: 111
31.01.2017, 16:38  [] 3
( . , ( , !) json. ) - ( id title). , json , .
0
Goal
513 / 415 / 140
: 31.10.2011
: 1,008
: 2
31.01.2017, 16:56 4
201 Created. The request has been fulfilled and resulted in a new resource being created.
0
TopLayer
785 / 584 / 302
: 23.10.2016
: 1,391
: 7
31.01.2017, 17:06 5
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void Main()
{
    var json = @"{""response"":[201, {""id"":1096,""title"":""I . . ѳ (.  . . )""},{""id"":1135,""title"":"" (.  (. ))""},{""id"":1140,""title"":"" .  - (.  . -)""},{""id"":1153,""title"":"" (.  (. ))""},{""id"":1231,""title"":"" (, )""},{""id"":1282,""title"":"" .   (.  . .  ( . . . ))""},{""id"":1656,""title"":"" (. ) (.  (. ))""},{""id"":1686,""title"":"" (. )""},{""id"":1892,""title"":"" ̳ ³ (. )""},{""id"":2866,""title"":"" ( Ҳ) (. )""},{""id"":2881,""title"":"" .   (.  . . )""},{""id"":2984,""title"":"" . . .    (.   )""},{""id"":3063,""title"":"" (. IJ, ) (.  (. ))""},{""id"":3216,""title"":""""},{""id"":3272,""title"":""޲   (.   )""},{""id"":3336,""title"":"" (. )""},{""id"":3502,""title"":"" . . (.  . . )""},{""id"":3750,""title"":"" . . . ""},{""id"":3814,""title"":"" () . ""},{""id"":3990,""title"":""""},{""id"":4013,""title"":"" (. )""},{""id"":4658,""title"":""""},{""id"":5181,""title"":""ʳ (. )""},{""id"":5616,""title"":"" (. )""},{""id"":6039,""title"":""""},{""id"":6400,""title"":"" ()""},{""id"":7020,""title"":""  (.   (. ))""},{""id"":7671,""title"":"" (. Ӳ) (.  (. ))""},{""id"":7959,""title"":""ʳ . .. - (.  () . . . -)""},{""id"":8384,""title"":"" ()""},{""id"":8496,""title"":""""},{""id"":8915,""title"":""""},{""id"":9426,""title"":"" ""},{""id"":9871,""title"":""""},{""id"":10220,""title"":"" (. ) (.  (. ))""},{""id"":10637,""title"":""²Ҳ (.  (.   Ȼ))""},{""id"":10973,""title"":""""},{""id"":11608,""title"":"" . . ""},{""id"":11837,""title"":""  (.  () )""},{""id"":11886,""title"":"" (. I) (.  (. ))""},{""id"":12610,""title"":""  ()  ""},{""id"":12624,""title"":""  . . .  (.   . . . )""},{""id"":12752,""title"":""""},{""id"":13061,""title"":"" (. ϲ) (.  (. ))""},{""id"":13607,""title"":""""},{""id"":15708,""title"":"" (. )""},{""id"":16215,""title"":"" . . . ""},{""id"":16713,""title"":"" (. )""},{""id"":16765,""title"":"" (. )""},{""id"":16908,""title"":""""},{""id"":17136,""title"":""""},{""id"":17612,""title"":""   ""},{""id"":17622,""title"":"" () (.  () )""},{""id"":18115,""title"":""IJ̳ . .  (.  . . )""},{""id"":18346,""title"":"" (.  (. ))""},{""id"":18594,""title"":"" ""},{""id"":18682,""title"":"" . .  (. ) (.  . .  (. ))""},{""id"":18973,""title"":""""},{""id"":19047,""title"":"" (. )""},{""id"":19281,""title"":"" (. ʲ, ) (.  (. , ))""},{""id"":19501,""title"":"" ( )""},{""id"":19504,""title"":""   ""},{""id"":20154,""title"":"" (.  (, ))""},{""id"":20383,""title"":""  ""},{""id"":21019,""title"":"" (. )""},{""id"":21202,""title"":""""},{""id"":21471,""title"":"" ()""},{""id"":22250,""title"":"" (. )""},{""id"":23088,""title"":"" () .  ""},{""id"":23174,""title"":""""},{""id"":23387,""title"":"" ()""},{""id"":23578,""title"":"" . ..  (.  . . . )""},{""id"":23942,""title"":"" (, )""},{""id"":24863,""title"":"" (. , ) (.  (. , ))""},{""id"":25282,""title"":"" (, , )""},{""id"":34004,""title"":""""},{""id"":34970,""title"":""""},{""id"":35599,""title"":"" . ""},{""id"":35643,""title"":""""},{""id"":39199,""title"":""""},{""id"":41226,""title"":""""},{""id"":41679,""title"":"" (KSE)""},{""id"":43042,""title"":""""},{""id"":62644,""title"":""""},{""id"":91571,""title"":""   .  ( 1994 .)""},{""id"":91934,""title"":"" ( 1990 .)""},{""id"":93413,""title"":"" .   ""},{""id"":105328,""title"":"" ""},{""id"":126961,""title"":"" ()""},{""id"":141734,""title"":""""},{""id"":141808,""title"":""  ( 2000 .)""},{""id"":167678,""title"":""""},{""id"":167838,""title"":"" ()   ""},{""id"":168167,""title"":""   Ȼ""},{""id"":168202,""title"":"" .  ()""},{""id"":170274,""title"":"" ""},{""id"":170275,""title"":"" ""},{""id"":170282,""title"":""-""},{""id"":170397,""title"":"" ""},{""id"":176164,""title"":""  . .  (.   . . )""}]}";
    var rootObject = (RootObject)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(RootObject));
    var rootObjectUniversity = new RootObjectUnivercity();
    rootObjectUniversity.response = rootObject.response.Skip(1).Select(jobj =>
    {
        dynamic d = jobj;
        return new Univercity { id = d.id, title = d.title };
    }).ToList();
}
 
public class RootObject
{
    public List<object> response { get; set; }
}
 
public class RootObjectUnivercity
{
    public List<Univercity> response { get; set; }
}
 
public class Univercity
{
    public int id { get; set; }
    public string title { get; set; }
}
0
0 / 0 / 0
: 04.08.2015
: 111
31.01.2017, 17:17  [] 6
C#
1
2
3
4
5
6
7
WebRequest wr = WebRequest.Create("https://api.vk.com/method/database.getUniversities?country_id=2&city_id=314");
            WebResponse wresp = wr.GetResponse();
            Stream s = wresp.GetResponseStream();
 byte[] b = new byte[1024];
                s.Read(b, 0, b.Length);
                var rootObj = JsonConvert.DeserializeObject<RootObjectUnivercity>(Encoding.UTF8.GetString(b));
                Console.WriteLine("OK");
: "Newtonsoft.Json.JsonSerializationException: Error converting value 201 to type ConsoleApplication3.ResponseUnivercity". Path 'response[0]', line 1, position 16. ---> System.ArgumentException: Could not cast or convert from System.Int64 to ConsoleApplication3.ResponseUnivercity."
, ResponseUnivercity RootObjectUnivercity.
0
TopLayer
785 / 584 / 302
: 23.10.2016
: 1,391
: 7
31.01.2017, 17:43 7
, dynamic
C#
1
2
3
4
5
    rootObjectUniversity.response = rootObject.response.Skip(1).Select(jobj =>
    {
        var d = (JObject)jobj;
        return new Univercity { id = (int)d.GetValue("id"), title = (string)d.GetValue("title") };
    }).ToList();
1
_exp10der_
Warrior
490 / 417 / 177
: 23.11.2014
: 932
31.01.2017, 23:38 8

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace ConsoleApplication293
{
    using System.Diagnostics;
    using System.Linq;
    using System.Net.Http;
    using System.Threading.Tasks;
    using Newtonsoft.Json.Linq;
 
    internal class Program
    {
        private static void Main() => MainAsync().Wait();
 
        private static async Task MainAsync()
        {
            using (var client = new HttpClient())
            {
                var content =
                    await client.GetStringAsync(
                        "https://api.vk.com/method/database.getUniversities?country_id=2&city_id=314");
 
                var json = JObject.Parse(content).SelectTokens("$.response[1:]");
 
                var universitets = json.Select(n => n.ToObject<University>()).ToList();
 
                Debugger.Break();
            }
        }
    }
 
    public class University
    {
        public int Id { get; set; }
        public string Title { get; set; }
    }
}
2
0 / 0 / 0
: 04.08.2015
: 111
01.02.2017, 13:30  [] 9
) , , , !
0
01.02.2017, 13:30
MoreAnswers
37091 / 29110 / 5898
: 17.06.2006
: 43,301
01.02.2017, 13:30

?
...

?
, :pardon: : ...


w_out UserControl. ...




:
9

- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
@Mail.ru