Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WP7中使用JSON信息解析2个不同的网站_C#_Json_Windows Phone 7_Json.net - Fatal编程技术网

C# 在WP7中使用JSON信息解析2个不同的网站

C# 在WP7中使用JSON信息解析2个不同的网站,c#,json,windows-phone-7,json.net,C#,Json,Windows Phone 7,Json.net,我在这个问题上停留的时间比我愿意承认的要长。让我解释一下我想做什么。我有一个网站,有一堆拍卖和他们的数据存储为一个JSON文件。我已经了解了如何使用JSON.net的反序列化程序解析JSON数据。现在,我需要做的是从拍卖清单中获取我解析的数据,然后在每次拍卖中使用商品id从另一个网站获取更详细的信息。以下是我到目前为止的情况: public AuctionSearch() { InitializeComponent(); WebClient proxy = new WebClie

我在这个问题上停留的时间比我愿意承认的要长。让我解释一下我想做什么。我有一个网站,有一堆拍卖和他们的数据存储为一个JSON文件。我已经了解了如何使用JSON.net的反序列化程序解析JSON数据。现在,我需要做的是从拍卖清单中获取我解析的数据,然后在每次拍卖中使用商品id从另一个网站获取更详细的信息。以下是我到目前为止的情况:

public AuctionSearch()
{
    InitializeComponent();
    WebClient proxy = new WebClient();
    proxy.OpenReadCompleted += new OpenReadCompletedEventHandler(get_auction_info);
    proxy.OpenReadAsync(new Uri("http://www.example.com/auctions/"));
}

void get_auction_info(object sender, OpenReadCompletedEventArgs e)
{
    Stream stream = e.Result;
    StreamReader sr = sr.ReadToEnd();
    var root = JsonConvert.DeserializeObject<AuctionListing>(result);
}
现在,我的问题来了。我正在尝试使用从JSON解析中获得的项目ID,并从另一个网站获取项目名称,该网站将显示项目名称和关于该项目的一系列其他信息。URL应该是这样的,然后我必须解析信息。一旦我解析了它,我就很难让名称与每次拍卖的其他物品信息相匹配。我有与上面基本相同的函数,但是解析到不同的类(当然)。我希望我已经提供了足够的信息,我正在努力为别人做什么来帮助我。如果我需要在这里发布我的完整代码,我可以,但它相当长。我认为我的问题与OpenReadAsync的工作方式有关,但我不确定。如果你们还有其他问题,请告诉我

澄清

我知道如何获取项目名称。我的问题是,我想存储来自两个解析的所有信息。下面是我的源代码。我会解释之后会发生什么

(continuation of the code from above)
void get_auction_info(object sender, OpenReadCompletedEventArgs e)
{
    (stuff from above)

    for (int i = 0; i < root[i].Length; i++)
    {
        WebClient client = new WebClient();
        client.OpenReadCompleted += new OpenReadCompletedEventHandler(auction_information);
        client.OpenReadAsync(new Uri("http://www.newexample.com/i/" + root[i].itemID + "/json"));

        TextBlock tb = new Textblock();
        tb.Text = (
                    "Auction ID #: " + root[i].auctionID +
                    "\nItem ID: " + root[i].itemID + "\n\n"
                  );
        tb.TextWrapping = TextWrapping.NoWrap;
        TextPanel.Children.Add(tb);
    }
}

void aucton_information(object sender, OpenReadCompletedEventArgs e)
{
    Stream stream = e.Result;
    StreamReader itemStreamReader = new StreamReader(stream);
    string theResult = itemStreamReader.ReadToEnd();

    var secondRoot = JsonConvert.DeserializeObject<AuctionInfo>(theResult);

    stream.Close();
    itemStreamReader.Close();
}
(上面代码的延续)
无效获取拍卖信息(对象发送者,OpenReadCompletedEventArgs e)
{
(上面的东西)
对于(int i=0;i

现在,我的问题是这个。一旦我调用拍卖信息OpenReadAsync中的第二个URL,它就不能像我期望的那样工作了。我想做的是能够从给定的itemID中获取项目名称,然后将其设置为itemName的变量。我不明白如何返回我刚刚从第二个JSON解析中获得的项目名称,并将其设置为第一个JSON调用中根对象中的itemID值。我希望这能有所帮助。

我不太清楚您的问题,但您是否希望在uri中包含itemID

您可以用与拍卖相同的方式进行:

public ItemSearch() 
{ 
    InitializeComponent(); 
    WebClient proxy = new WebClient(); 
    proxy.OpenReadCompleted += new OpenReadCompletedEventHandler(get_item_info); 
    proxy.OpenReadAsync(new Uri("http://www.example.com/i/" + auction.itemID.ToString() + "/json")); 
} 

如果问题是在用于解析特定项的回调中获取itemID,则可以使用eventargs e获取uri并从中过滤id

澄清了我的原始问题,因此我希望这可能会有所帮助。
public ItemSearch() 
{ 
    InitializeComponent(); 
    WebClient proxy = new WebClient(); 
    proxy.OpenReadCompleted += new OpenReadCompletedEventHandler(get_item_info); 
    proxy.OpenReadAsync(new Uri("http://www.example.com/i/" + auction.itemID.ToString() + "/json")); 
}