Originally posted by Protocol Penguin
View Post
Announcement
Collapse
No announcement yet.
The Programming Thread (was New to Programming)
Collapse
This is a sticky topic.
X
X
-
Last edited by Brad; 02-11-2020, 16:02.
-
Originally posted by dataDave View PostI'm building a Perfect Dark clone in Unity.
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
-
Originally posted by randombs View PostHow's that work?
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
-
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; } }
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 PostI 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.
Take a look here
Last edited by ZipZap; 11-11-2020, 23: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
-
Originally posted by randombs View PostGotcha, 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.
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
-
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, 10: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
Comment