Reputation: 1814
I have this problem when deserializing a serialized JSON into a C# object using Newtonsoft
JsonConvert. I am on a linux platform and using MonoDevelop.
I am getting following error message in terminal:
Missing method DeserializeObject in assembly /home/deepalj/tmp/c#temp/SerializerTest/SerializerTest/bin/Debug/SerializerTest.exe, type Newtonsoft.Json.JsonConvert
Following is the code for deserialization:
using System;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
namespace SerializerTest
{
class MainClass
{
public static void Main (string[] args)
{
Payment p = Newtonsoft.Json.JsonConvert.DeserializeObject<Payment> ("{ id: 10, card: 'visa', amount: 1}");
Console.WriteLine ("Card: "+p.card+"\n"+"Amount: "+p.amount);
}
}
}
Following is the Payment
class:
using System;
namespace SerializerTest
{
public class Payment
{
public int id { get; set; }
public string card { get; set; }
public decimal amount { get; set; }
}
}
Any help to fix this would be helpful.
Thanks.
Upvotes: 1
Views: 899
Reputation: 1814
I figured out the solution. Instead of adding Newtonsoft.Json
as a package with References->Edit References->Packages , I included its .net assembly manually using References->Edit References->.Net Assembly. I downloaded Newtonsoft json pakage here and added its Bin/Net45/Newtonsoft.Json.dll as a .net assembly. Now it works well.
Upvotes: 2