Home C# building a string for JSON using variables
Reply: 0

C# building a string for JSON using variables

user986
1#
user986 Published in July 23, 2018, 1:36 pm

I'm relatively new to C# and trying to deserialize a string from JSON for this value; ["format"]["tags"]["ENCODER"]

// Manually building the string works fine
string test = (dict["format"]["tags"]["ENCODER"]);    

string found_value = "";

const char quote = '\u0022';

string encoder = "[" + quote + "format" + quote + "][" + quote + "tags" + quote + "][" + quote + "ENCODER" + quote + "]";

// Just as a test
encoder = encoder.Replace("\u005c\u0022", "\u0022");   

// This Fails   
found_value = (dict[encoder]); 

It throws an exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll but was not handled in user code Additional information: The given key was not present in the dictionary.

So I'm sure it's the way I'm passing the encoder string. Probably something really simple but I've spent hours trying various things and become blind to it now.

Thanks in advance

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.467028 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO