![]() |
| (Symbolbild) |
30. Mai 2014
Software ist so ein Weichei
Labels: Code
21. Mai 2014
JsonTree Library and Nuget Package for Quick and Easy JSON Parsing

Any time a piece of my software receives a JSON message it must dive into the JSON and extract parameters. Sometimes the JSON is deeply nested and parameters are buried inside arrays of objects of arrays.
I want to access these parameters quickly without dissecting the JSON by looping and if-ing through the layers. In other words: I want single line expressions to dive into JSON and extract values.
You can call it XPath for JSON, but a language integrated compiled way, which his much faster, than XPath and supported by IntelliSense (autocomplete).
Example JSON:
[ "first", { "aString": "HelloWorld", "aNumber": 42 } ]Extract the value 42:
var fourtytwo = json.List[1].Dictionary["aNumber"].Int;The JsonTree library basically maps JavaScript Arrays to C# Lists and a JavaScript Objects to C# Dictionaries. It is then very easy to enumerate lists of dictionaries of lists, etc as single line expressions to extract values. Also, if looping is required, it is done on well known container classes List<...> and Dictionary<string,...>.
A more complex example:
var data = "[ { aInt: 41, bBool: true, bLong: 42000000000, cString: "43", dFloat: 3.14159265358979323 }, { aInt: 44, bLong: 45000000000, cString: "46" }, { aList: [ { aInt: 47, bString: "48" }, { aInt: 49, bString: "50" } ], bMap: { aInt: 51, bString: "52" } } ]";Extracting the 50 as integer number. The 50 is a string value in a JS object (of key "bString") in a JS array (as second element) in a JS object (with key "aList") in a JS array (as third element).
var fifty = new JsonTree.Node(data).Array[2].Object["aList"].Array[1].Object["bString"].Int;JsonTree uses either JavaScript notation with Array and Object as keywords or C# notation with List and Dictionary as keywords. Choose whatever you like more.
The same as above in C# notation:
var fifty = new JsonTree.Node(data).List[2].Dictionary["aList"].List[1].Dictionary["bString"].Int;Other examples:
var pi = new JsonTree.Node("{a:3.1415927}").Dictionary.First().Value.Float;You can use JsonTree as nuget package: https://www.nuget.org/packages/JsonTree/
var pi = new JsonTree.Node("{a:3.1415927}").Dictionary["a"].Float;
Or check out the source code on Google code: https://code.google.com/p/json-tree/
JsonTree also includes a flexible JSON serializer which is used to create a easy to read debug view of the JSON structure. Browsing the JSON in debug mode is a real highlight.
The serializer can also be used to add elements to a deserialized JSON node and re-serialize.
_happy_parsing()
PS: I know that I could use NewtonSoft JSON with C# dynamic and JObject
PS: I know that I could use LINQ
I like this way, because it relies only on plain old CLR objects, List and Dictionary.
13. Mai 2014
Statistisch Spenden: Regeln
Habe den SpendenCache immer dabei. Ich suche immer Abnehmer. Abnehmer freuen sich. Ich freue mich. Soweit alles klar.
Aber in der Praxis kommen trotzdem Fragen auf, z.B.:
- "Der hat vorhin schon mal was bekommen. bekommt der nochmal?"
- "Mensch und Hund sind zwei. Bekommt der Hund auch was?"
- "Da sammelt einer Flaschen. bekommt der auch was?"
- "Das ist Lärm aber keine Musik. Bekommt der wirklich was dafür?"
- "Heute schon viele Abnehmer gefunden und SpendenCache ist leer. Bekommt der nächste nichts?"
- "Mein Kumpel ist nicht bedürftig, fragt aber trotzdem, um sich einen Jux zu machen. Bekommt der?"
Der Sinn von Statistisch Spenden ist ES ZU TUN, ohne lange über Fragen und Antworten nachzudenken. Deshalb gilt der Grundsatz:
Jeden Tag einen Euro spenden an Jeden der fragt, solange der Vorrat reicht.
Daraus lassen sich Regeln für die Praxis ableiten:
- Jeder jeden Tag einmal.
- Offener Becher, offene Hand, offener Geigenkästen gelten als Frage.
- Hund: nein. der fragt nicht. Herrchen fragt.
- Kumpel: ja. Jeder, der fragt ohne Ausnahme. Das vergeht ihm schon mit der Zeit.
- Musik schlecht: trotzdem. Die Frage zählt.
- Der Flaschensammler fragt nicht, außer er fragt. (Oft sind auch Flaschensammler dankbar, aber es gibt auch ein paar, die darauf bestehen, dass sie keine Almosen nehmen, sondern Flaschen sammeln. Also lieber nicht aufdrängen, sondern auf die Frage warten, es gibt noch genug Abnehmer.)
- Nicht horten. Das muss raus.
- Nicht sparen und aufteilen damit alle gleichmäßig bekommen. Andere kümmern sich um die anderen.
- Ist der SpendenCache leer, dann ist er leer. Morgen geht's weiter. Kein Stress.
- Ist der SpendenCache zu voll, dann nicht alles einfach der Kollekte geben. Statistisch Spenden ist zusätzlich zu dem was du sonst machst. Spende Brot für die Welt oder Mikrokredite oder der Umwelt. Trotzdem bleibt der Grundsatz. Statistisch jeden Tag einen Euro an Jeden der fragt. Also: Anstrengen und SpendenCache abbauen. Abnehmer suchen. Wenn nötig, auf 2 Euro Einheiten umstellen. Das wird schon.
_happy_giving()
Labels: Realwelt, Statistisch Spenden
2. Mai 2014
Statistisch Spenden ist Win-Win
Ich trage immer den SpendenCache von LENDENSHURZ mit mir herum und weil mein täglicher Weg mich nicht oft an Bedürftigen (Abnehmer) vorbeiführt, wird der SpendenCache immer dicker. Ich bin deshalb immer froh, wenn ich Gelegenheit habe den Cache abzubauen.
Ich freue mich über jeden, der mir einen Becher entgegenhält, über jeden, der auf der Straße musiziert und den Geigenkasten offen hat. Manchmal laufe ich extra an den Stellen vorbei, an denen oft Abnehmer stehen, damit ich mein Versprechen erfüllen kann.
Das ist sicher eine positive Entwicklung aus der Sicht der Abnehmer. Ich habe ein Interesse was los zu werden. Sie haben ein Interesse was zu bekommen. Klassische win-win Situation.
_happy_winning()
Labels: Realwelt, Statistisch Spenden
25. Februar 2014
Visual Studio 2010 Projects Always Out of Date Solved by Changing the File Date
If your Developer Studio suddenly tells you, that your project is "out of date". If it keeps telling you, even though you rebuild all. If a simple F5 always pops the annoying "These projects are out of date" dialog box, then ...
... you probably ran into a bug that lets Visual Studio think, that a totally unrelated file on your disk is a dependency of your project(s). This file probably has been added to your disk recently and for unknown reasons Visual Studio regards it as dependency.
In my case its "C:\PROGRAMDATA\NVIDIA CORPORATION\DRS\NVDRSDB0.BIN" from a newly installed Nvidia driver. Other files have also been reported like "C:\PROGRAMDATA\SOPHOS\SOPHOS ANTI-VIRUS\CONFIG\CONFIG.BOPS".
There might be other reasons for this behavior, like missing header files. These can be resolved easily, by adding the missing file or removing it from the solution.
This article is about solving the case of "Visual Studio Project Out Of Date Because of Weird Dependency".
The standard way to solve this is to
1. find out which file claims to be newer than your project.
2. Exclude the offending file.
Step 1:
Enable Visual Studio debugging and check the log. Basically:
in
%ProgramFiles(x86)%\Microsoft Visual Studio\10.0\Common7\IDE\
after
</configSections>
insert
<system.diagnostics>
<switches>
<add name="CPS" value="4" />
</switches>
</system.diagnostics>Then use DgbView to get the log output.Step 2:
There seem to be ways to exclude the file or folder from the list of dependencies. This can be done for each project or system wide (which is probably what you want).
I am not a fan of changing details in large XML config files with weak documentation and multiple possible insertion points of which only one works and the others make things worse, and which affects all projects.
But I still tried.
Unfortunately, I do not get these solutions to work. My project still wants to rebuild every time.
There is another solution:
Just change the "modified" file date of the offending file.I am using Attribute Changer to date the file back by 2 years (or whatever). Simple and works.
For the record: I download tools like Attribute Changer only from trusted software repositories. You should too. Do not download from the "homepage" of the program. Anyone can make a homepage and send you anything.
_happy_attributing()
Labels: Code
17. November 2013
SpendenCache von LENDENSHURZ
Wir erinnern uns: Jeden Tag einen Euro spenden.
Endlich fliegen die Euros nicht mehr lose in der Hosentasche herum. Schluss mit klimpern.
Ab jetzt leise, hygienisch, stylisch, immer verfügbar.
_happy_caching()
UPDATE: Ich komme momentan nicht hinterher. Sammle täglich einen Euro. Bin schon auf 2 € Stücke umgestiegen. Trotzdem wird der Stapel immer höher. Meine Laufstrecken im Alltag treffen so selten auf Bedarf. Sollte wohl mehr in der Innenstadt rumlaufen. Will nicht auf Bulk-Spenden für Eisbären/Taifun/Sahel/Amnesty ausweichen. Das ist extra, wäre zu einfach. Die Regel lautet: "Statistisch 1€ pro Tag an Bedürftige", die dich persönlich fragen, egal was du sonst machst.
Labels: Alltag, memcache, Realwelt, Statistisch Spenden
22. Oktober 2013
Which Star Trek Character Are You?
Mein Ergebnis vom "Which Star Trek character are you?" Quiz...
You are Data:
|
Even though you are a genius you are always striving to be better. |
Und wenn wir schon dabei sind "Which Star Wars character are you?"
You are Qui-Gon Jinn:
| Overall, you're a pretty well balanced person. But maybe you focus a little too much on the here and now. Think about the future before its too late. |
|





