Announcement

Collapse
No announcement yet.

The Programming Thread (was New to Programming)

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Originally posted by Protocol Penguin View Post
    “**** you, got mine” isn’t a constructive attitude. I’ve had enough of people boasting about their perceived abilities. That doesn’t help anyone.
    No one's boasting and to be honest I've had just about enough of your whining in this thread. Please don't post in here anymore; it's not helping anyone and it's bringing the vibe right down. In case that's not clear that's an instruction not a request. This forum software doesn't have a way to ban someone from a topic so our only recourse if you continue to try to post in here will be a more general ban.
    Last edited by Brad; 02-11-2020, 17:02.

    Comment


      I'm building a Perfect Dark clone in Unity.

      Comment


        Originally posted by dataDave View Post
        I'm building a Perfect Dark clone in Unity.
        How's that work?

        I'm scared to even google Unity, although it was an option when I installed Visual Studio.

        Right now I'm trying to create a Jason parser that will take the Jason file Skype gave me so I can organise my Japanese lessons into a better format than speech bubbles. I've already tried Skype's own parser and it's just a web page with boxes of text.

        You best believe I'll be adding an option to press X to JASON

        Comment


          var obj = JsonConvert.DeserializeObject<T>(json);

          there you go. I'm assuming you mean JSON rather than his deformed brother.

          Comment


            Originally posted by randombs View Post
            How's that work?
            I honestly don't know, yet. I'm working it out gradually. I like what the BallisticNG dev did for his Wipeout love letter, so why not have a dabble?

            I'm just sick of hopelessly waiting for a new game which uses the Goldeneye engine. The plan is to get a proof of concept working and then try pitching it to someone.

            Comment


              Originally posted by MartyG View Post
              var obj = JsonConvert.DeserializeObject<T>(json);

              there you go. I'm assuming you mean JSON rather than his deformed brother.
              Yeah don't create your own JSON parser. This is a solved problem.

              Comment


                Thanks, guys.

                I worded it wrong. I'm not making a parser so much as trying to make a program that will take the json file and that Skype created and turn it into something I can work with, like a list or a linq thingy. Then I can output the messages to something useful like an Excel file, or even a CSV file. I've never used json before so I'll need to figure out what I'm doing.

                I found out VisualStudio can paste the contents of a json file as Classes so I pasted the json file into a new Skype.cs file.

                It looks like this:
                Code:
                public class Rootobject
                        {
                            public string userId { get; set; }
                            public string exportDate { get; set; }
                            public Conversation[] conversations { get; set; }
                        }
                
                public class Conversation
                        {
                            public string id { get; set; }
                            public string displayName { get; set; }
                            public float version { get; set; }
                            public Properties properties { get; set; }
                            public Threadproperties threadProperties { get; set; }
                            public Messagelist[] MessageList { get; set; }
                        }
                But before I can even get my head around all that, it turns out the json file that Skype created was dodgy(7-zip would give an unexpected end of file error no matter how many times I exported the data from the Skype website).

                I've spent the past hour cleaning it up using a lovely website called JSON Viewer (https://codebeautify.org/jsonviewer) which helped me fix the issues and remove all unrelated conversation/call information so now it's just the messages from the Japanese lessons left.

                It's almost 1am so I'll call it quits for now and try again tomorrow. And by 'tomorrow' I mean 'today'

                Comment


                  Originally posted by randombs View Post
                  I worded it wrong. I'm not making a parser so much as trying to make a program that will take the json file and that Skype created and turn it into something I can work with, like a list or a linq thingy.
                  This is called deserialisation, it's what the code MartyG posted will do. It will take a JSON string and convert it into an instance of the class you've made.

                  Take a look here
                  Learn how to use the System.Text.Json namespace to serialize to JSON in .NET. Includes sample code.
                  Last edited by ZipZap; 12-11-2020, 00:36.

                  Comment


                    Thanks!

                    I've been a bit busy with work and Xboxes but that website converted the JSON to XML which might also be easy to work with if I can't get this class going. In the meantime, my wife had the brilliant idea of having me ask the Japanese teacher to use Google Docs so now we use that during the lesson. Still,there's six months of chat bubbles I want to get through!

                    Let this be a lesson to people learning to program. It's not wise to be random and just dive in like I did. Sure, it's fun spending a few hours on a Friday afternoon at work making a program that helps test if aluminium foil in your wallet really does stop the contactless cards clashing with your Oyster card(true story), but you'll soon reach a point where trying to learn the foundations is boring. Learn them when you're fresh so you can't ignore them!

                    Comment


                      Your intermediary (XML or JSON) shouldn't make any difference to what ends up in the class, you're just using it as a way to transfer the data from one place to another (serializing and deserializing).

                      XML is easier to read as it tends to look more structured, but the files end up being a lot larger. So long as your classes have properties that match those in the intemediary file, they'll deserialize fine (you'll just need a different deserializer).

                      You can have additional properties in your classes and tell the deserializer to ignore them with property attributes (they sit above the property in [] brackets such as [jsonignore] that property then won't be looked for in the intermediary file when converted into the solid class object.

                      Comment


                        Gotcha, I'm going to investigate now. I think the trouble is I just used VS to create the class code but the class doesn't do anything. It's just the stuff I posted above. I think I need to do something so I can create an object and fill it with the json data using the class.

                        Comment


                          Originally posted by randombs View Post
                          Gotcha, I'm going to investigate now. I think the trouble is I just used VS to create the class code but the class doesn't do anything. It's just the stuff I posted above. I think I need to do something so I can create an object and fill it with the json data using the class.
                          Those clases you've made are fine for your data, but yes you will then want to add some code in another file that interacts with them.

                          Assuming your json matches the class properties, it should be something simple like...

                          var jsonString = File.ReadAllText(fileName);
                          var obj = JsonSerializer.Deserialize<Rootobject>(jsonString) ;

                          The first line loads your json file to a string, the second deserializes the json to an instance of the Rootobject class.

                          As for just diving in, once I'd grasped a few basics, that's pretty much how I learnt to code! I have come to realise these days that it's generally good to search "best way to....." before doing something new, but if you're pretty new to coding this sounds like a reasonable challenge to set yourself. You'll learn something from it and your end results will be far more satisfying!

                          Comment


                            Thanks, I'll work on it tomorrow and/or the weekend and let you guys know how I get on.

                            Comment


                              As ZipZap says, they're just your classes to hold the data.

                              You're going to start getting into design patterns to actually do something with them and that will depend on what it is you're intending to do with that data ultimately.

                              It's all part of the analysis, design, implement, test and release cycle.

                              For this you might want to look at the Mediator design pattern - you'll have some kind of manager object that does the work to get the JSON from your source and then deserializes that data into your class objects (your data models). Those objects can then be consumed by whatever process does something with them, be that displaying the data in a UI or storing it in a database, etc.
                              Last edited by MartyG; 12-11-2020, 11:47.

                              Comment


                                I won't lie - I'm a little scared of letting you boys down after the Protocol Penguin shenanigans

                                I've been using classes in my programs since seeing my manager using them and finding my way around. So far they're just used to hold multiple lists. For example:

                                1) Order class which holds lists based on the below two classes:

                                2) OrderHeader class holds strings, ints, bools and dates related to order headers(account number, order date, free shipping, etc)

                                3) OrderItem class holds data on the items themselves(item name, barcode, current status, etc)

                                2 an 3 just contain declarations like public int AccountNumber{ get; set; }

                                I can't do anything useful with them until I do things like List<OrderHeader>().

                                Once I've done that, I can do things like:

                                int accountNumber = order.orderHeader[0].AccountNumber;

                                or use foreach to loop through every AccountNumber in order.orderHeader

                                I'm fine with that stuff.

                                So when I look at the json class I posted before, I see a bunch of declarations and now need to figure out how to interact with them, just like what you and ZipZap said.

                                Comment

                                Working...
                                X