Click here to Skip to main content
15,891,940 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
what if text which I wants to deserialize one value without name?
Posted
Comments
Christian Graus 21-Aug-12 8:35am    
This makes zero sense. When your 'question' is the same as your 'subject', that's a good clue that you've not taken the time to ask a clear question. A name value pair can include a value that is blank, but it cannot include a value without a name.
dmitrij1990 21-Aug-12 8:39am    
Thanks, but what field I need to make in class for blank value?

OK, now I see what you want. You can create blank values in the settings file, just leave them blank, but you have to leave the VALUE blank, you can't have a variable or a setting that has a value, but no name. string.Empty denotes an empty string, you don't need to create something in code to have an empty string available to you as a property. Why do you need this ?

I think you need to probably post some code and explain WHY you want what you want, if I have not answered you correctly already.
 
Share this answer
 
Comments
dmitrij1990 21-Aug-12 8:48am    
Thanks, string which i need to deserialize contains besides pairs "name - value" and one number(there are list of messages and number(count))..in class I create field Message..but what field i should create for number??
Christian Graus 21-Aug-12 8:50am    
An int or float field, I guess. Serialisation will handle storing and retrieving your class instance, but if you need to store a number, use a numeric variable type.
It depends on the parser.

I have used Newtonsoft parser to serialize/deserialize Json object,
Check the code below,

internal struct namestruct
    {
        public string fname { get; set; }
        public string lname { get; set; }
    }
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
     string json =
            @"{
               ""name"":{
                  ""fname"":""Sandip"",
                  ""lbname"":""Nascar""
               },
               ""name_0"":{
                  ""fname"":""Jon"",
                  ""lbname"":""Doe""
               }, 
               ""name_1"":{
                  ""fname"":""Michael"",
                  ""lbname"":""Ferrara""
               },
               """":{
                  ""fname"":""No Name"",
               },
        }";


     var values = JsonConvert.DeserializeObject<dictionary><string,>>(json);
     string valuefname_1 = values["name_0"].fname;

     string valuenoname_1 = values[""].fname;//see. I have accessed it with name having Empty.String
</dictionary>


Hope this helps.
cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900