Convert json string to .NET object in Xamarin

I read several other people who had this question and I tried to use these approaches. However, I get strange results that I cannot fix.

I use http://json2csharp.com/# to create classes that I use with the convert method.

in my code I use the following libraries

using System;
using RestSharp;
using Newtonsoft.Json;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Collections.Generic;
using ZXing;
using ZXing.Mobile;

I have a method created to take a json string from my api call and convert it to C # objects using Json.NET

public void convert(String response)
{
    Console.WriteLine("Response: " + response);
    Console.WriteLine("Check 1");
    var list = JsonConvert.DeserializeObject<List<RootObject>>(response);
    Console.WriteLine("Check 2");
    Console.WriteLine(list);
    Console.WriteLine("Check 3");
    for (int i = 0; i < list.Count; i++) // Loop with for.
    {
        Console.WriteLine("Check 4");
        Console.WriteLine("Pass: " + i);
        Console.WriteLine(list[i]);
    }
    Console.WriteLine("Check 5");
}

public class Item
{
    public string barcode { get; set; }
    public string name { get; set; }
    public string upvotes { get; set; }
    public string downvotes { get; set; }
    public string updated { get; set; }
}

public class RootObject
{
    public List<Item> items { get; set; }
}

Here is an example dataset from an API that I am calling

{
  "items":[
   {
     "barcode": "12345",
     "name": "xxx",
     "upvotes": "0",
     "downvotes": "0",
     "updated": "1465103701673"
  },
  {
     "barcode": "1234",
     "name": "xxx",
     "upvotes": "0",
     "downvotes": "0",
     "updated": "1465103697375"
   },
   {
     "barcode": "123",
     "name": "xxx",
     "upvotes": "0",
     "downvotes": "0",
     "updated": "1465103688554"
   }
]}

Errors do not appear in the error log.

If I try to add debugging as soon as I delete by line

var list = JsonConvert.DeserializeObject<List<RootObject>>(response);

I get the message "Frame not in Module"

1, , , . Debug Visual Studio , , convert.

    06-05 16:32:59.391 D/Mono    ( 3672): Assembly Ref addref PennyGeneral[0x813fcad0] -> Newtonsoft.Json[0x82201ac8]: 2
    06-05 16:32:59.391 D/Mono    ( 3672): The request to load the retargetable assembly mscorlib v2.0.5.0 was remapped to mscorlib v2.0.5.0
    06-05 16:32:59.391 D/Mono    ( 3672): Assembly Ref addref Newtonsoft.Json[0x82201ac8] -> mscorlib[0x76d8a880]: 12
    Response: {"items":[{"barcode": "12345","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103701673"},{"barcode": "1234","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103697375"},{"barcode": "123","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103688554"}]}
    06-05 16:32:59.392 I/mono-stdout( 3672): Response: {"items":[{"barcode": "12345","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103701673"},{"barcode": "1234","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103697375"},{"barcode": "123","name": "xxx","upvotes": "0","downvotes": "0","updated": "1465103688554"}]}
    Check 1
    06-05 16:32:59.393 I/mono-stdout( 3672): Check 1
    06-05 16:32:59.393 D/Mono    ( 3672): Remapped public key token of retargetable assembly System.Core from 7cec85d7bea7798e to b77a5c561934e089
    06-05 16:32:59.393 D/Mono    ( 3672): The request to load the retargetable assembly System.Core v2.0.5.0 was remapped to System.Core v2.0.5.0
    06-05 16:32:59.394 D/Mono    ( 3672): Unloading image System.Core.dll [0x85f686d0].
    06-05 16:32:59.394 D/Mono    ( 3672): Image addref System.Core[0x85f660f0] -> System.Core.dll[0x82d98df8]: 4
    06-05 16:32:59.395 D/Mono    ( 3672): Config attempting to parse: 'System.Core.dll.config'.
    06-05 16:32:59.395 D/Mono    ( 3672): Config attempting to parse: '/Users/builder/data/lanes/3236/ee215fc9/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/System.Core/System.Core.config'.
    06-05 16:32:59.395 D/Mono    ( 3672): Assembly Ref addref Newtonsoft.Json[0x82201ac8] -> System.Core[0x82df1b18]: 4
    06-05 16:32:59.427 D/Mono    ( 3672): Remapped public key token of retargetable assembly System from 7cec85d7bea7798e to b77a5c561934e089
    06-05 16:32:59.427 D/Mono    ( 3672): The request to load the retargetable assembly System v2.0.5.0 was remapped to System v2.0.5.0
    06-05 16:32:59.428 D/Mono    ( 3672): Unloading image System.dll [0x85fb77d0].
    06-05 16:32:59.428 D/Mono    ( 3672): Image addref System[0x85fb94b0] -> System.dll[0x830252a0]: 4
    06-05 16:32:59.428 D/Mono    ( 3672): Config attempting to parse: 'System.dll.config'.
    06-05 16:32:59.428 D/Mono    ( 3672): Config attempting to parse: '/Users/builder/data/lanes/3236/ee215fc9/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/System/System.config'.
    06-05 16:32:59.428 D/Mono    ( 3672): Assembly Ref addref Newtonsoft.Json[0x82201ac8] -> System[0x8302f6e0]: 4
    06-05 16:32:59.475 D/Mono    ( 3672): Remapped public key token of retargetable assembly System.Runtime.Serialization from 7cec85d7bea7798e to b77a5c561934e089
    06-05 16:32:59.475 D/Mono    ( 3672): The request to load the retargetable assembly System.Runtime.Serialization v2.0.5.0 was remapped to System.Runtime.Serialization v2.0.5.0
    06-05 16:32:59.476 D/Mono    ( 3672): Image addref System.Runtime.Serialization[0x86002d60] -> System.Runtime.Serialization.dll[0x86002098]: 1
    06-05 16:32:59.476 D/Mono    ( 3672): Assembly System.Runtime.Serialization[0x86002d60] added to domain RootDomain, ref_count=1
    06-05 16:32:59.476 D/Mono    ( 3672): AOT module 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/PennyGeneral.PennyGeneral-2/libaot-System.Runtime.Serialization.dll.so" not found
    06-05 16:32:59.477 D/Mono    ( 3672): AOT module '/Users/builder/data/lanes/3236/ee215fc9/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app-lib/PennyGeneral.PennyGeneral-2/libaot-System.Runtime.Serialization.dll.so" not found
    06-05 16:32:59.477 D/Mono    ( 3672): Unloading image data-0x8602f008 [0x86002f78].
    06-05 16:32:59.478 D/Mono    ( 3672): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
    06-05 16:32:59.478 D/Mono    ( 3672): Config attempting to parse: '/Users/builder/data/lanes/3236/ee215fc9/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
    06-05 16:32:59.478 D/Mono    ( 3672): Assembly Ref addref Newtonsoft.Json[0x82201ac8] -> System.Runtime.Serialization[0x86002d60]: 2
    Loaded assembly: System.Runtime.Serialization.dll [External]
    06-05 16:32:59.478 D/Mono    ( 3672): Assembly Ref addref System.Runtime.Serialization[0x86002d60] -> mscorlib[0x76d8a880]: 13
    06-05 16:32:59.500 D/Mono    ( 3672): Assembly Ref addref System.Core[0x82df1b18] -> System[0x8302f6e0]: 5
    Loaded assembly: Anonymously Hosted DynamicMethods Assembly [External]
    Thread finished: <Thread Pool> #5
    06-05 16:33:09.774 D/Mono    ( 3672): [0x834fab30] worker finishing
    06-05 16:33:09.781 D/dalvikvm( 3672): threadid=16: bye!
    The thread 'Unknown' (0x5) has exited with code 0 (0x0).
    Thread finished: <Thread Pool> #7
    06-05 16:33:37.391 D/Mono    ( 3672): [0x85274538] worker finishing
    06-05 16:33:37.398 D/dalvikvm( 3672): threadid=20: bye!
    The thread 'Unknown' (0x7) has exited with code 0 (0x0).
    Thread finished: <Thread Pool> #8
    06-05 16:33:53.046 D/Mono    ( 3672): [0x851f1b60] worker finishing
    06-05 16:33:53.052 D/dalvikvm( 3672): threadid=19: bye!
    The thread 'Unknown' (0x8) has exited with code 0 (0x0).
    Thread finished: <Thread Pool> #3
    06-05 16:33:59.536 D/dalvikvm( 3672): threadid=15: bye!
    The thread 'Unknown' (0x3) has exited with code 0 (0x0).
    Thread started: <Thread Pool> #10
    Thread started: <Thread Pool> #11
    06-05 16:34:39.062 D/dalvikvm( 3672): threadid=15: interp stack at 0x83950000
    06-05 16:34:39.064 D/dalvikvm( 3672): threadid=16: interp stack at 0x83970000
    06-05 16:34:39.065 D/Mono    ( 3672): [0x834fa728] worker starting
    Thread finished: <Thread Pool> #11
    06-05 16:34:59.711 D/Mono    ( 3672): [0x834fa728] worker finishing
    06-05 16:34:59.717 D/dalvikvm( 3672): threadid=16: bye!
    The thread 'Unknown' (0xb) has exited with code 0 (0x0).
+4
1

. ...

var root = JsonConvert.DeserializeObject<RootObject>(response);
var list = root.items;
+3

All Articles