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 6128037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:34:52+00:00 2026-05-23T16:34:52+00:00

I’m trying to deserialize a relative simple JSON string, which looks like: [{ FacebookID:

  • 0

I’m trying to deserialize a relative simple JSON string, which looks like:

[{
    "FacebookID": "00000000000000",
    "Items": [{
        "BillID": "75a9ca7b-3b79-4db0-9867-83b2f66021d2",
        "FacebookID": "0000000000",
        "Description": "Some description",
        "Amount": 5000,
        "Accepted": false
    }]
}, {
    "FacebookID": "00000000000000",
    "Items": [{
        "BillID": "cec0a6d2-1db9-4a12-ae43-f61c6c69f0a6",
        "FacebookID": "0000000000",
        "Description": "Some description",
        "Amount": 3250,
        "Accepted": false
    }, {
        "BillID": "aaf51bb3-4ae6-48b5-aeb6-9c4d42fd4d2a",
        "FacebookID": "0000000000",
        "Description": "Some more..",
        "Amount": 100,
        "Accepted": false
    }]
}, {
    "FacebookID": "0000000000",
    "Items": [{
        "BillID": "2124cbc4-2a48-4ba4-a179-31d4191aab6a",
        "FacebookID": "0000000000",
        "Description": "even more..",
        "Amount": 300,
        "Accepted": false
    }]
}]

nothing fancy as you see.. except for the Items array, but that shouldnt really be a problem.

If we then make up a few types that matches the json-string, and a function that will deserialize the string and map it to the types we’ll end up with something like:

[<DataContract>]
type Item = 
  { [<field: DataMember(Name = "BillID")>]
    BillID : string
    [<field: DataMember(Name = "FacebookID")>]
    FacebookID : string
    [<field: DataMember(Name = "Description")>]
    Description : string
    [<field: DataMember(Name = "Amount")>]
    Amount : int
    [<field: DataMember(Name = "Accepted")>]
    Accepted : bool }

[<DataContract>]
type Basic = 
  { [<field: DataMember(Name = "FacebookID")>]
    FacebookID : string 
    [<field: DataMember(Name = "Items")>]
    Items : Item array }

// My function to deserialize the json string, and map it to the given type.
let deserializeJson<'a> (s:string) =
  use ms = new MemoryStream(ASCIIEncoding.Default.GetBytes s)
  let serialize = DataContractSerializer(typeof<'a>)
  serialize.ReadObject ms :?> 'a

let get (url:string) =
  use web = new WebClient()
  web.DownloadString url

// Returns the JSON string
let result = deserializeJson<Basic array> <| get "http://some.com/blabla"

Instead of doing its job, it simply throws following exception, when it’s trying to deserialize the string:

Unhandled Exception:
System.Runtime.Serialization.SerializationException:
There was an error deserializing the
object of type
System.Collections.Generic.IList`1
[[Program+Basic, ConsoleApplication1,
Version=0.0.0.0, Culture=neutral,
PublicKe yToken=null]]. The data at
the root level is invalid. Line 1,
position 1.

Am I missing something? – The JSON-string is perfectly valid…

  • 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-05-23T16:34:53+00:00Added an answer on May 23, 2026 at 4:34 pm

    The serializer you are using is for XML you want to use DataContractJsonSerializer.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.