Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 返回格式错误的JSON的JSON.net_Web Services_Json_Json.net - Fatal编程技术网

Web services 返回格式错误的JSON的JSON.net

Web services 返回格式错误的JSON的JSON.net,web-services,json,json.net,Web Services,Json,Json.net,我用它来解析对象,并将它们传递给我创建的Web服务。这些对象是LINQ对象。当我使用JQuery访问此Web服务时,它无法正确解析JSON。格式似乎有问题 我得到的JSON字符串如下: [{"typeid":1, "typename":"binders", "description":"test", "RESOURCEs": [{"resourceid":4, "resourcename":"Binders 1", "description":"Pak

我用它来解析对象,并将它们传递给我创建的Web服务。这些对象是LINQ对象。当我使用JQuery访问此Web服务时,它无法正确解析JSON。格式似乎有问题

我得到的JSON字符串如下:

[{"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":[]
     }
    ]
 }]

有人知道为什么这不起作用吗?

我想这是一个编码问题,如果你把它从记录中删除怎么办

"resourcename":"Rødblyant 1"

确保您在两侧都使用UTF-8。我的猜测是,要么您正在使用默认编码(如windows1252)对字符串进行编码,要么接收端正在执行类似的操作

请记住,JSON必须是UTF-8、UTF-16(LE或be)或UTF-32(LE或be)格式


为了测试这一点,去掉所有
å
ø
字符,看看它是否有效。如果是这样的话,它肯定是一边编码一边编码。

这里的实际问题是,这个JSON被嵌入到XML标记中。我通过使用以下解析器解析JSON字符串解决了这个问题:

当然,这并不理想,因为JQuery应该为我做到这一点,但直到我找到一种方法让.NET webservices返回原始JSON字符串,而不是嵌入到XML标记中,这个解决方案才起作用=)