Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8133945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:49:33+00:00 2026-06-06T09:49:33+00:00

I am trying to make a single dataclass that holds information from both Facebook

  • 0

I am trying to make a single dataclass that holds information from both Facebook and Twitter.

but in my JSON reply from twitter I need id_str and from FaceBook I get id.

I need those two to be put into the id-string.

Now I know I can use [JsonProperty("id_str")] if I want to deserialize Twitters id_str into my id-string.

But what if I need both Facebook’s id and Twitters id_str to be deserialized in the same id-string I have in my dataclass?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:49:35+00:00Added an answer on June 6, 2026 at 9:49 am

    No, this is not possible.

    Let’s take a look at the Json.NET documentation. In particular the help page about the JsonPropertyAttribute class.

    To quote:

    “Instructs the JsonSerializer to always serialize the member with the specified name.”

    It’s declared in the Newtonsoft.Json namespace. We need to determine how it is declared. Let’s take a look at the Json.NET’s source code on CodePlex:

    http://json.codeplex.com/

    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property |     
     AttributeTargets.Parameter, AllowMultiple = false)]
    public sealed class JsonPropertyAttribute : Attribute
    {
        //...
    }
    

    Guess that answers the question. The AllowMultiple property of the attribute is set to false. So you can’t decorate a property, field or parameter more than once with this attribute.

    Even if you could how do you expect Json.net to figure out which attribute to use? I would create types for Twitter and Facebook separately into which you can deserialize the received JSON data.

    So:

    Twitter -> JSON -> Twitter specific types
    Facebook -> JSON -> Facebook spefic types
    

    Then create an abstraction which your application uses instead of addressing these types directly. They just belong to a specific social media implementation.

    Twitter / Facebook / … speficic types -> Your types

    If you directly try to deserialize the data into your “common types”, then you are just going to keep struggling because they don’t align 100% with the received data and you’ll wind up with some funky, hard to maintain deserialization logic.

    Another option is to create your own custom Json.NET converter.

    http://geekswithblogs.net/DavidHoerster/archive/2011/07/26/json.net-custom-convertersndasha-quick-tour.aspx

    Just create a converter for Twitter and Facebook and when you deserialize the JSON data, just specify which converter you want to use.

    • TwitterConverter
    • FacebookConverter

    E.g.:

    MySocialType myType = JsonConvert.DeserializeObject<Mapped>(json, 
        new TwitterConverter());
    

    Anyway I would try to avoid polluting your class types with the deserialization logic itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a query that grabs a single row from an SQL
I’m trying to make an über-simple (single-character) prompt that gives me as much information
I'm trying to make a query that looks at a single table to see
I am trying to make an AJAX call from several domains to a single
I am trying to MAKE / Compile a single AOSP project from the repository
I am trying to make a bash script that will transfer a file from
I am trying to make a query that will insert multiple values from my
I am trying make long screen to vertical direction. So, I need a screen
Trying to make a custom :confirm message for a rails form that returns data
Trying to make simple minesweeper game in python, but have one problem. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.