views:

417

answers:

3

Hey,

I am using json.net to parse objects and delivering them to a webservice I have made. The objects are LINQ-objects. When I access this webservice with JQuery, it doesn't parse the JSON correctly. There seems to be something wrong with the formatting..

The JSON-string I get is this one:

[{"typeid":1,
  "typename":"binders",
  "description":"test",
  "RESOURCEs":
    [{"resourceid":4,
      "resourcename":"Binders 1",
      "description":"Pakke med hele fire binders!!!",
      "typeid":1,
      "RESERVATIONLINEs":[]
     },    
     {"resourceid":10,
      "resourcename":"xxx",
      "description":"xxx",
      "typeid":1,
      "RESERVATIONLINEs":[]
     }
    ]
 },
 {"typeid":2,
  "typename":"blyant",
  "description":"også dyrt",
  "RESOURCEs":
    [{"resourceid":5,
      "resourcename":"Gråblyant 1",
      "description":"Fin og grå",
      "typeid":2,
      "RESERVATIONLINEs":[]
     },
     {"resourceid":6,
      "resourcename":"Rødblyant 1",
      "description":"Må spisses ofte",
      "typeid":2,
      "RESERVATIONLINEs":[]
     }
    ]
 },
 {"typeid":4,
  "typename":"Penn",
  "description":"tester",
  "RESOURCEs":
    [{"resourceid":7,
      "resourcename":"Penn 1",
      "description":"Blå og fin",
      "typeid":4,
      "RESERVATIONLINEs":[]
     },
     {"resourceid":11,
      "resourcename":"xxx",
      "description":"xxx",
      "typeid":4,
      "RESERVATIONLINEs":[]
     }
    ]
 },
 {"typeid":5,
  "typename":"Kajakk",
  "description":"Dette er en type båt",
  "RESOURCEs":
    [{"resourceid":1,
      "resourcename":"Havkajakk 1",
      "description":"FOr havbruk",
      "typeid":5,
      "RESERVATIONLINEs":[]
     },
     {"resourceid":2,
      "resourcename":"Havkajakk 2",
      "description":"For havbruk",
      "typeid":5,
      "RESERVATIONLINEs":[]
     }
    ]
 },
 {"typeid":6,
  "typename":"3G-modem",
  "description":"Fra NetCom",
  "RESOURCEs":
    [{"resourceid":3,
      "resourcename":"3G-modem 1",
      "description":"Gammelt og ustabilg",
      "typeid":6,
      "RESERVATIONLINEs":[]
     },
     {"resourceid":12,
      "resourcename":"xxx",
      "description":"xxx",
      "typeid":6,
      "RESERVATIONLINEs":[]
     }
    ]
 },
 {"typeid":7,
  "typename":"Minnepinne",
  "description":"på 1 KB",
  "RESOURCEs":
    [{"resourceid":8,
      "resourcename":"Minnepinne 1",
      "description":"1 KB (!)",
      "typeid":7,
      "RESERVATIONLINEs":[]
     },
     {"resourceid":9,
      "resourcename":"Minnepinne 2",
      "description":"20 PB",
      "typeid":7,
      "RESERVATIONLINEs":[]
     }
    ]
 }]

Anyone have a clue why this is not working?

A: 

I guess this is an encoding problem, what if you remove this from your record?

"resourcename":"Rødblyant 1"
J-16 SDiZ
A: 

Make sure you are working with UTF-8 on both sides. My guess is that either you are encoding the string using the default encoding (like windows1252), or the receiving end is doing something similar.

Remember that JSON must be in UTF-8, UTF-16 (LE or BE), or UTF-32 (LE or BE).

To test this, get rid of all of the å and ø characters and see if it works. If so, it's definitely encoding on one side or the other.

lavinio
+2  A: 

The actual problem here was that this JSON was embedded in a XML-tag. I solved the problem by parsing the JSON-string by using this parser: http://www.json.org/js.html

Of cource this is not ideal, as JQuery should do this for me, but until I find a way for .NET-webservices to return the raw JSON-string, not embedded in a XML-tag, this solution works =)

Espenhh