Resolved Working with Json

ProtekNickz

Member
Joined
Jan 13, 2022
Messages
14
Programming Experience
5-10
Hi , I'm just trying to figure out how to get the data as I wish, I have a Json file I made and checked in an online formatter, here's my code I'm using to get the inline selection needed

search through Json:
            string MySpacer = Environment.NewLine;
            foreach (var MyItem in _cont._Customer)
            {
                if (MyItem._Name == CustomerName.Text)
                {
                    if(MyItem.Surname== Surname.Text)
                    {
                        Details.Text = $"{ MyItem._Name } { MySpacer } { MyItem._Surename } { MySpacer } {  _Address = MyItem._Address }";
                    }
                }
            }

I can already read the Json file quite well which looks like

Json:
{"_Customer": [
{"_Address": "1231", "_Name": "Joe1", "Surename": "Shmo1"},
{"_Address": "1232", "_Name": "Joe2", "Surename": "Shmo2"},
{"_Address": "1233", "_Name": "Joe3", "Surename": "Shmo3"},
{"_Address": "1234", "_Name": "Joe4", "Surename": "Shmo4"},
{"_Address": "1235", "_Name": "Joe5", "Surename": "Shmo5"},
{"_Address": "1236", "_Name": "Joe6", "Surename": "Shmo6"},
{"_Address": "1237", "_Name": "Joe7", "Surename": "Shmo7"}
]}

and this are just examples of something I'm putting together, So here's what I'm trying to do basically mix and match the data which is loaded in the json, So I can pick Joe1 with Shmo4 and address 1233,
My above C# code works great getting the data inline, but I want to be able to mix and match it in some sort of IF statement, If Joe1 then dont get his details get all others in a stringbuilder, to collect all the other data say to just get all the surnames but not joe1's, I hope someone understands me xD.

Thanks in Advance,

ProtekNickx xD.
 
It's ok folks, I've figured it out what it was I needed to do, in this code:

C#:
            string MySpacer = Environment.NewLine;
            foreach (var MyItem in _cont._Customer)
            {
                if (MyItem._Name == CustomerName.Text)
                {
                    if(MyItem.Surname== Surname.Text)
                    {
                        Details.Text = $"{ MyItem._Name } { MySpacer } { MyItem._Surename } { MySpacer } {  _Address = MyItem._Address }";
                    }
                }
            }

            //I changed this line to
            if (MyItem._Name != CustomerName.Text)

Which solved my problem, I didn't want to mix it up as such, but just make a selection and if i selected Joe1 Shmoe1 then get data of others and not selected, I should have though about the operators xD,

well take care all,

ProtekNickz xD.
 
Back
Top Bottom