-4

I'm somehow having troubles deserializing a json string into a simple List or string[] (I don't care which).

As of what I know, this is how to do this job:

JsonConvert.DeserializeObject<List<string>>(jsonString);

Here I am getting a RuntimeBinderException. It complains about the parameter, although my json string is valid and simple: a:1:{i:0;s:10:"Sahibinden";}

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
Cutaraca
  • 2,069
  • 3
  • 14
  • 21
  • 5
    Your JSON isn't valid. Paste it into http://json2csharp.com. If you haven't given us the full string, please do so. – James Gould Jan 05 '17 at 15:23
  • 1
    Your JSON is also not an array, so it cannot be deserialized into a list. – Erik Philips Jan 05 '17 at 15:24
  • I didn't know there were different json syntaxs between programming languages. Here it worked: http://www.unserialize.com/s/06402092-abe2-3969-82f4-0000513f719e Thanks guys, I will do some research. – Cutaraca Jan 05 '17 at 15:29
  • There `are not` different JSON syntax between programming languages. There `are` different serialization syntax between them. A serialized object is not a JSON object. – Jorge Fuentes González Jan 05 '17 at 15:41

2 Answers2

1

What you have isn't JSON is a serialized PHP object. There have been some tools that work well with this in C# but there isn't native support. If you own the PHP, then convert the object/array to JSON first. If not try the information on this question: https://stackoverflow.com/a/1923626/474702

Community
  • 1
  • 1
reckface
  • 5,678
  • 4
  • 36
  • 62
0

Your JSON is invalid. Problems:

  1. a:1 should be inside an object bracket of {}

  2. The : before the { is invalid, you need a , there

  3. The ; just after i:0 is invalid, you need a comma there

  4. You repeat the mistake described in 1. and 2. inside your {} brackets as well

Solution: You need to read about JSON and make sure you understand its syntax.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175