Palak Shah
Well-known member
- Joined
- Apr 29, 2020
- Messages
- 97
- Programming Experience
- 1-3
I had JSON string which I converted to JSON Class, and now I want to add Dictionary method insode my JSON class which will return me certain values from JSON class variables
And for that I am facing an issue including Dictionary method in Json class c#
Can someone help where can I include that method?
But I'm getting compile time error as " a field initializer cannot reference the nonstatic field ", so I'm not able to understandhow and where should I include my method which will work
And for that I am facing an issue including Dictionary method in Json class c#
Can someone help where can I include that method?
My JSON Class Model:
namespace JsonModel
{
using Newtonsoft.Json;
using System.Collections.Generic;
public partial class StringResourcesX
{
[JsonProperty("StringResources")]
public StringResources StringResources { get; set; }
}
public partial class StringResources
{
[JsonProperty("Culture")]
public Culture Culture { get; set; }
public Culture_ Culture_ { get; set; }
public FullName FullName { get; set; }
public Dictionary<Culture_, FullName> CulturalNames { get; set; }
}
public partial class Culture
{
[JsonProperty("Cultures")]
public Cultures Cultures { get; set; }
[JsonProperty("CulturalName")]
public CulturalName CulturalName { get; set; }
}
public partial class CulturalName
{
[JsonProperty("AE")]
public AE AE { get; set; }
[JsonProperty("GB")]
public GB GB { get; set; }
}
public partial class AE
{
[JsonProperty("AE_Name")]
public string AE_Name { get; set; }
[JsonProperty("AE_LastName")]
public string AE_LastName { get; set; }
}
public partial class GB
{
[JsonProperty("GB_Name")]
public string GB_Name { get; set; }
[JsonProperty("GB_LastName")]
public string GB_LastName { get; set; }
}
public partial class Cultures
{
[JsonProperty("Culture_UK")]
public string Culture_UK { get; set; }
[JsonProperty("Culture_US")]
public string Culture_US { get; set; }
[JsonProperty("Culture_CA")]
public string Culture_CA { get; set; }
[JsonProperty("Culture_DE")]
public string Culture_DE { get; set; }
[JsonProperty("Culture_JP")]
public string Culture_JP { get; set; }
}
public enum Culture_
{
GB,
US,
IT,
FR,
CA,
DE,
SE,
NL,
NZ,
AU,
AE,
CN,
JP,
IE,
IN,
ES
}
public class FullName
{
public string First;
public string Last;
public FullName(string first, string last)
{
this.First = first;
this.Last = last;
}
}
}
Method Which I want to include in class model:
public static Dictionary<Culture_, FullName> CulturalNames = new Dictionary<Culture_, FullName>
{
{Culture_.GB, new FullName(Culture.CulturalName.GB.GB_Name, Culture.CulturalName.GB.GB_LastName)},{Culture_.AE, new FullName(Culture.CulturalName.AE.AE_Name, Culture.CulturalName.AE.AE_LastName)}
};
But I'm getting compile time error as " a field initializer cannot reference the nonstatic field ", so I'm not able to understandhow and where should I include my method which will work