使用 JSON.NET 解析 PHP 生成的 JSON

发布于 2024-08-23 06:06:40 字数 351 浏览 3 评论 0原文

我确信之前已经有人问过这个问题,但我没有找到我需要的信息,所以我想我应该发布这个。

我编写了一个 PHP 脚本,它返回一个简单的 JSON 对象,如下所示:

{"status":"success","level":"admin"}

我正在执行一个标准 Web 请求,将所需的数据提交到通过互联网编写脚本,效果很好。

现在,我想使用 JSON.NET 提取各个变量,这样我就可以知道“状态”和“级别”的值是什么。问题是,我不知道从哪里开始。

我在 VB.NET(在 .NET Compact Framework 上)中执行此操作。有人可以帮助我吗?我在谷歌上花了两个小时,却一无所获!

谢谢!

I'm sure this has been asked before but I'm not finding quite the information I'm needing so I thought I'd post this.

I've written a PHP script that returns a simple JSON object that looks like this:

{"status":"success","level":"admin"}

I'm doing a standard web request that submits the required data to the script over the internet and that's working fine.

Now, I want to use JSON.NET to pull out the individual variables so I can know what the values of "status" and "level" are. The problem is, I have no idea where to start.

I'm doing this in VB.NET (on the .NET Compact Framework). Can anyone help me? I've spent the last 2 hours on Google and can come up with nothing!

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请你别敷衍 2024-08-30 06:06:41

我认为下面的代码片段会有用。

从此处粘贴内容 http://msdn.microsoft.com/en -us/library/bb299886.aspx#intro_to_json_topic5

string jsonText = @"[""Europe"", ""Asia"", ""Australia"", ""Antarctica"",
 ""North America"", ""South America"", ""Africa""]";

using (JsonTextReader reader = new JsonTextReader(new StringReader(jsonText)))
{
    while (reader.Read())
    {
        if (reader.TokenClass == JsonTokenClass.String &&
            reader.Text.StartsWith("A"))
        {
            Console.WriteLine(reader.Text);
        }
    }
}

i think below code snippet will be useful.

Pasting the content from here http://msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_topic5

string jsonText = @"[""Europe"", ""Asia"", ""Australia"", ""Antarctica"",
 ""North America"", ""South America"", ""Africa""]";

using (JsonTextReader reader = new JsonTextReader(new StringReader(jsonText)))
{
    while (reader.Read())
    {
        if (reader.TokenClass == JsonTokenClass.String &&
            reader.Text.StartsWith("A"))
        {
            Console.WriteLine(reader.Text);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文