Click here to Skip to main content
15,888,002 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,
I am facing issue while string property declaration.
My requirement is need to declare the property like below but i am getting the error.
public string AUS.GNAF_PID { get; set; }
.
I want declare like above.
I am getting the some output from API. that output data is JSON format and i need compare those column values with My class.
For example i am getting the API response output is like below
{
    
    "GeoCountryISO3" : "AUS",
    "AUS.GNAF_PID" : "GAQLD156218414",
    "user_fields" : 2987
}

and i have created property class like below.
we cannot able to change the Endpoint name
public class GeocodingOutputRecord
    {
        
        public string GeoCountryISO3 { get; set; }
        public string UniqueId { get; set; }
       
        public string AUSGNAF_PID { get; set; }


        
    }

Here if declared
AUSGNAF_PID 
like this
public string AUS.GNAF_PID { get; set; }
getting the error.

Any one could you please help me to resolve this issue.

What I have tried:

I have tried so many options but it's not working
Posted
Updated 13-Dec-22 4:21am

Try this:
C#
public class GeocodingOutputRecord
{
    public string GeoCountryISO3 { get; set; }

    [JsonProperty("AUS.GNAF_PID")]
    public string AUSGNAF_PID { get; set; }
    public int user_fields { get; set; }
}
That should tell the JSON processor which class property matches which JSON name.
 
Share this answer
 
You must convert the JSON into an instance of the Class GeocodingOutputRecord.

In that Class definition you use the underscore "_". which is legal. Your JSON example uses the dot.

Do not use the dot '.' in C# property names: it is a look-up operator.

Your example implies that "AUF" is a class.

You need to review how a Class instance is written in JSON, and how it is read/transformed from JSON back int0 Class instance.
 
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