English 中文(简体)
混杂 纽约总部
原标题:Parsing complex JSON

我想就工作计划7对一个复杂的初等人物进行区分。 第一夫人 我必须把一名JSON的饲料捆绑起来,我将数据检索到第二名JSON的饲料中。

To parse the first feed I use this web service http://horaires-ter-sncf.naholyr.fr/prochainsdeparts.php?gare=... after that we use the code and the station s name to parse the second feed http://horaires-ter-sncf.naholyr.fr/prochainsdeparts.php?gare=....&id=...

我的这部法律,但却没有奏效:

public static class Parser
        {
            public static string resultats;
            public static reponse[] obj = new reponse[]{new reponse(),new reponse()};
            public static reponse1 obj1 = new reponse1();


            public static void HttpsCompleted_reponse(object sender, DownloadStringCompletedEventArgs e)
            {
                Horaire hre =new Horaire();
                  try
                {
                    var ms = new MemoryStream(Encoding.Unicode.GetBytes(resultats));
                    var ser = new DataContractJsonSerializer(typeof(reponse1));
                    obj1 = (reponse1)ser.ReadObject(ms);

                }

                catch
                {

                    WebClient wc = new WebClient();
                    //wc.DownloadStringCompleted += HttpsCompleted_reponse1;
                    wc.DownloadStringAsync(new Uri("http://horaires-ter-sncf.naholyr.fr/prochainsdeparts.php?gare=" +hre.gettxt()));
                    Debug.WriteLine("youuuuuuuuuuuuuuuuuuuuuuuppppppppppiiii");
                }

            }
            /*
            public static void HttpsCompleted_reponse1(object sender, DownloadStringCompletedEventArgs e)
            {
                try
                {
                    var ms = new MemoryStream(Encoding.Unicode.GetBytes(resultats));
                    var ser = new DataContractJsonSerializer(typeof(Gare));
                    obj1 = (reponse1)ser.ReadObject(ms);

                }

                catch
                {

                    WebClient wc = new WebClient();
                        wc.DownloadStringCompleted += HttpsCompleted_reponse;
                        wc.DownloadStringAsync(new Uri("http://horaires-ter-sncf.naholyr.fr/prochainsdeparts.php?gare=" + obj.success.Gares.Eleme + "&id=" + obj.success.id));

                }

            }

        */

        }
        public class Depart
        {
            [DataMember(Name = "type")]
            public string type { get; set; }
            [DataMember(Name = "heure")]
            public string heure { get; set; }
            [DataMember(Name = "destination")]
            public string destination { get; set; }
            [DataMember(Name="attention")]
            public string attention { get; set; }
            [DataMember(Name = "retards")]
            public string [] retards { get; set; }
            [DataMember(Name = "source")]
            public string source { get; set; }
            public Depart()
            {
            }
        }

        public class Success {
            [DataMember(Name = "nom")]
            public string nom { get; set; }
            [DataMember(Name = "id")]
            public int id { get; set; }
            [DataMember(Name = "departs")]
            public Depart[] departs { get; set; }
                    public Success() 
                    {
                        this.departs = new Depart[0];
                    }
             }
        public class Success1
        {
            [DataMember(Name="Gares")]
            public Gare[] Gares { get; set; }
                public Success1()
                {
                    this.Gares = new Gare[0];
                }
        }
        public class Gare{


            [DataMember(Name="Nom")]
            public string Nom { get; set; }
            [DataMember(Name="code")]
            public int code { get; set; }
                public Gare() 
                {
                }
        }

        public class reponse
        {

            [DataMember(Name = "code")]
            public string code{get;set;}
            [DataMember(Name = "success")]
            public Success1 success{get;set;}
                public reponse()
                {
                    this.success = new Success1();
                }
             }
        public class reponse1 {
            [DataMember(Name = "code")]
            public string code { get; set; }
            [DataMember(Name = "success")]
            public Success success { get; set; }
                public reponse1() 
                {
                    this.success = new Success();
                }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //for (int i=0; i<=Parser.obj1.Length;i++)
            Debug.WriteLine(Parser.obj1.success.nom);
        }
    }
问题回答

你的法典存在几个问题。 但是,即使你解决了这些问题,你也一定能够把接收站的清单与放在箱子之外。

Explanation:

该网站提供你正在使用的网络服务。

{"code":201,"success":{"gares":{"villefranche-d alb.-ce":1750,"villefranche de rgue-12":1749,...}}}

检查这些站点及其识别资料:

(19)

这是一个联系阵列,其关键和价值没有明确与“凯”和“Value”挂钩。 但是,这些评分对于使JSON教化是必要的。 它们必须采用格式

[{“Key”:“villefranche-d alb.-ce”,“Value”:“1750”},{“Key”:“villefranche de rgue-12”,“Value”:“1749”}]

页: 1 (原因是该序列器支持的种类比int更复杂,可用作关键和价值。)

该博客员额载有对这一事项和如何使用<代码>的非常好的说明。 JavacastSerializer 可能的解决办法。 但不幸的是,这一类是银灯的。

有更多的人面临类似问题:

<>Solution:

使用Json.NET

look。 NET应当向您提供林克2json和简单的序列。





相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签