Linq query JObject

后端 未结 4 1101
日久生厌
日久生厌 2021-01-19 01:15

I am using Json.net for serializing and then making an JObject that looks like this:

 \"RegistrationList\": [
    {
      \"CaseNumber\": \"120654-1330\",
           


        
4条回答
  •  太阳男子
    2021-01-19 02:09

    I think you want to get the JSON string like below:

    {
    'RegistrationList': [       
                {
                    'CaseNumber': '120654-1330',
                                        'Priority': 5,
                                        'PersonId': 7,
                                        'Person': {
                                            'FirstName': '0',
                                            'LastName': '',
                                        },
                                        'UserId': 7,
                                        'User': {
                                            'Id': 7,
                                            'CreatedTime': '2013-07-05T13:09:57.87',
                                            'Comment': ''
                                        }
                                    },
                                    {
                                        'CaseNumber': '120654-1330',
                                        'Priority': 5,
                                        'PersonId': 7,
                                        'Person': {
                                            'FirstName': '0',
                                            'LastName': '',
                                        },
                                        'UserId': 7,
                                        'User': {
                                            'Id': 7,
                                            'CreatedTime': '2013-07-05T13:09:57.87',
                                            'Comment': ''
                                        }
                                    },
                                ]
    }
    

    If so, you can get below code working for your question:

                string json = @"{
                                'RegistrationList': [
                                    {
                                        'CaseNumber': '120654-1330',
                                        'Priority': 5,
                                        'PersonId': 7,
                                        'Person': {
                                            'FirstName': '0',
                                            'LastName': '',
                                        },
                                        'UserId': 7,
                                        'User': {
                                            'Id': 7,
                                            'CreatedTime': '2013-07-05T13:09:57.87',
                                            'Comment': ''
                                        }
                                    },
                                    {
                                        'CaseNumber': '120654-1330',
                                        'Priority': 5,
                                        'PersonId': 7,
                                        'Person': {
                                            'FirstName': '0',
                                            'LastName': '',
                                        },
                                        'UserId': 7,
                                        'User': {
                                            'Id': 7,
                                            'CreatedTime': '2013-07-05T13:09:57.87',
                                            'Comment': ''
                                        }
                                    },
                                ]
                            }";
            JObject o = JObject.Parse(json);
            JArray list = (JArray)o["RegistrationList"];
            List> rList = new List>();
            foreach (var r in list)
            {
                Tuple temp = new Tuple(r["CaseNumber"].Value(), r["Person"]["FirstName"].Value(), r["User"]["Comment"].Value());
                rList.Add(temp);
                Console.WriteLine(temp);
            }
    

提交回复
热议问题