JSON验证 [英] JSON validation

查看:195
本文介绍了JSON验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用iPhone上的json-framework来解析json字符串。
当我调用这个方法时:

I'm trying to work with json-framework on iPhone to parse a json string. When I'm calling this method:

NSDictionary *dictionary = [jsonString JSONValue];

我收到错误:

"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Object value expected for key:
 Options\" UserInfo=0x4b5f390 {NSUnderlyingError=0x4b5f320 \"Expected value while
 parsing array\", NSLocalizedDescription=Object value expected for key: Options}"

根据这个json验证器[1]: http://www.jsonlint.com//我的json无效。但是这样吗??

According to this json validator [1]: http://www.jsonlint.com// my json is not valid. But is that so??

我的json字符串如下所示:

My json string looks like this:

{
"Options": [
    {
        "ID": "7",
        "A": "1",
        "EAt": new Date(2011,
        0,
        7,
        12,
        30,
        0),
        "Type": "Binary",       
    } 
}

* 编辑Json :(仍带来错误)

* Edited Json: (still brings up an error)

{
"Options": [
    {
        "ID": "7",
        "A": "1",
        "EAt": new Date(2011,
        0,
        7,
        12,
        30,
        0),
        "Type": "Binary"       
    } 
 ]
}


推荐答案


  1. 删除后的逗号...二进制

  2. 在两个}之间添加一个}}。

  3. 日期不能像这样使用,请参阅如何格式化Microsoft JSON日期? http: //msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_sidebarb

  1. remove the comma after ...Binary"
  2. add a ] between the two } }.
  3. Date cant be used like this, see How do I format a Microsoft JSON date? and http://msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_sidebarb

这是有效的:

{
    "Options": [
        {
            "ID": "7",
            "A": "1",
            "EAt": "new Date(2011,0,7,12,30,0)",
            "Type": "Binary" 
        } 
    ] 
}

这篇关于JSON验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆