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

  • SEARCH
  • Home
  • 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 8622971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:10:38+00:00 2026-06-12T07:10:38+00:00

plz help, I’m stuck. I have a WCF service which returns something like this:

  • 0

plz help, I’m stuck.
I have a WCF service which returns something like this:

{
   "GetDataRESTResult":
     [
       {"Key1":100.0000,"Key2":1,"Key3":"Min"},
       {"Key1":100.0000,"Key2":2,"Key3":"Max"}
     ]
}

and I would like to deserialize it, but whatever I use (JSON.NET or DataContractJsonSerializer) I’m getting errors.
When using DataContractJsonSerializer I’m using theis code:

byte[] data = Encoding.UTF8.GetBytes(e.Result);
MemoryStream memStream = new MemoryStream(data);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<DataDC>));
List<DataDC> pricinglist = (List<DataDC>)serializer.ReadObject(memStream);

where DataDC is the data contract which I’ve got from the service reference of the WCF REST service I’m getting the JSON data from, and the error I’m getting is InvalidCastException…

Trying to use JSON.NET I get another exception, but still nothing I can figure out, can anyone help please?

EDIT
Here’s a JSON.NET stacktrace:

Cannot deserialize the current JSON object (e.g. {“name”:”value”})
into type
‘System.Collections.Generic.List`1[MyApp.MyServiceReference.DataDC]’
because the type requires a JSON array (e.g. [1,2,3]) to deserialize
correctly. To fix this error either change the JSON to a JSON array
(e.g. [1,2,3]) or change the deserialized type so that it is a normal
.NET type (e.g. not a primitive type like integer, not a collection
type like an array or List) that can be deserialized from a JSON
object. JsonObjectAttribute can also be added to the type to force it
to deserialize from a JSON object. Path ‘GetDataRESTResult’, line 1,
position 23.

  • 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-12T07:10:39+00:00Added an answer on June 12, 2026 at 7:10 am

    Below code works

    string json = @" {""GetDataRESTResult"":[{""Key1"":100.0000,""Key2"":1,""Key3"":""Min""},{""Key1"":100.0000,""Key2"":2,""Key3"":""Max""}]}";
    
    dynamic dynObj = JsonConvert.DeserializeObject(json);
    foreach (var item in dynObj.GetDataRESTResult)
    {
        Console.WriteLine("{0} {1} {2}", item.Key1, item.Key3, item.Key3);
    }
    

    You can also use Linq

    var jObj = (JObject)JsonConvert.DeserializeObject(json);
    var result = jObj["GetDataRESTResult"]
                    .Select(item => new
                    {
                        Key1 = (double)item["Key1"],
                        Key2 = (int)item["Key2"],
                        Key3 = (string)item["Key3"],
                    })
                    .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck in a deep problem right now. Plz help me with this....
am getting this error when i open my site in internet explorer......... plz help
I'm new to json , so plz do help me on this. I'm trying
plz help me to resolve this i m a learner [Session started at 2011-01-10
my dear Friends I am new to this java ..so plz help me thank
I am new to javascript and jquery guys plz help, I have a list
Plz help me on this Table Structure ID(primary key) Text To find a text
i face this problem with the updating plz help An error occurred while collecting
please someone help out from this headaround problem of me; I have dynamically created
plz help me for this error and ... (visual studio 2010) void file_remove(u32 id,

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.