JSON.NET 读取器问题

发布于 2024-10-16 22:03:56 字数 1110 浏览 0 评论 0原文

得到了这种格式

{ "models": [
    {
        "id":1,
        "modelName":"dfdsf",
        "created":{
            "userFullname":"demo",
            "time":"150301",
            "date":"20110208",
            "userId":"123"
        },
        "remark":"dsfdf",
        "updated":"~unique-id~1"
    },
    {
        "id":2,
        "modelName":"test",
        "created":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110210",
            "userId":"124"
        },
        "remark":"test",
        "updated":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110209",
            "userId":"test"
        }
    }
]}

当我从 spring .json 生成 .json 文件时,我遇到了一些问题,我第一次使用 JObject Parse 进行转换时

JObject job = JObject.Parse(fullJson);

,另一方面我使用 jtoken 来关注“模型”,

JToken jDetail = job["models"];

但问题是 {[{ xxx }]} 它看起来像 jarray 我不知道如何转换它

我曾经使用过 JArray、JsonTextReader 但它不起作用。

可以建议一些吗?因为如果我通过这个 ll 我会为对象设置一些值。

谢谢你的每一个想法。

i got some problem when i generate .json file from spring .json ,and i got this format

{ "models": [
    {
        "id":1,
        "modelName":"dfdsf",
        "created":{
            "userFullname":"demo",
            "time":"150301",
            "date":"20110208",
            "userId":"123"
        },
        "remark":"dsfdf",
        "updated":"~unique-id~1"
    },
    {
        "id":2,
        "modelName":"test",
        "created":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110210",
            "userId":"124"
        },
        "remark":"test",
        "updated":{
            "userFullname":"test",
            "time":"150301",
            "date":"20110209",
            "userId":"test"
        }
    }
]}

first time i used JObject Parse for convert

JObject job = JObject.Parse(fullJson);

and the other hand i used jtoken to focus "models"

JToken jDetail = job["models"];

but the problem is {[{ xxx }]} it look like jarray i don't have any idea to convert it

i ever use JArray, JsonTextReader but it doesn't work.

could suggestion some? because if i pass this ll i set some value to object.

thank you for every idea.

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

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

发布评论

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

评论(1

卷耳 2024-10-23 22:03:56
string fullJson = File.ReadAllText("TextFile1.txt"); // for brevity
var job = JObject.Parse(fullJson);
var models = job.Value<JArray>("models");
Console.WriteLine(models[0]);

结果:

{
  "id": 1,
  "modelName": "dfdsf",
  "created": {
    "userFullname": "demo",
    "time": "150301",
    "date": "20110208",
    "userId": "123"
  },
  "remark": "dsfdf",
  "updated": "~unique-id~1"
}
string fullJson = File.ReadAllText("TextFile1.txt"); // for brevity
var job = JObject.Parse(fullJson);
var models = job.Value<JArray>("models");
Console.WriteLine(models[0]);

result:

{
  "id": 1,
  "modelName": "dfdsf",
  "created": {
    "userFullname": "demo",
    "time": "150301",
    "date": "20110208",
    "userId": "123"
  },
  "remark": "dsfdf",
  "updated": "~unique-id~1"
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文