Javascript 自定义字符串-缺少:在属性列表之后

Javascript 自定义字符串-缺少:在属性列表之后,javascript,jquery,string-formatting,Javascript,Jquery,String Formatting,我一直在使用我编写的php类编译$.ajax数据。数据如下所示: { 0: [ { Status : "example status 2" , Contact ID Number : "1" , Date Entered : "2011-06-15" , Date Assigned : "2011-06-15" , Date Last Modified : "2011-06-15" , Deceased Date : "" , Link

我一直在使用我编写的php类编译$.ajax数据。数据如下所示:

{ 
0: [ 
    { Status : "example status 2"
    , Contact ID Number : "1"
    , Date Entered : "2011-06-15"
    , Date Assigned : "2011-06-15"
    , Date Last Modified : "2011-06-15"
    , Deceased Date : ""
    , Linked To Registrant 1 : "Leona Brown"
    , Relationship 1 : "Father"
    , Authorization 1 : "1"
    , Linked To Registrant 2 : "Henry Sale"
    , Relationship 2 : "Husband"
    , Authorization 2 : "1"
    , Location : "Hamilton Harron Funeral Home"
    , Sales Manager : "Dan Thompson"
    , Counselor : "Mike Brown"
    , Registration Number : "1"
    , Registration Date : "2001-05-11"
    , Program 1 Number : "2"
    , Program 1 Date : "2003-11-05"
    , Program 1 Name : "Non Registrant Test Program - Advantage"
    , Program 2 Number : "--"
    , Program 2 Date : "--"
    , Program 2 Name : "--"
    , First Name : "Onelia"
    , Last Name : "Garcy"
    , Address Location 1 : "home"
    , Address 1 : ""
    , City 1 : "Houston"
    , State/Province 1 : "Texas"
    , Zip/Postal Code 1 : "77019"
    , Home Phone : "--"
    , Work Phone : "--"
    , Mobile Phone : "--"
    , Pager : "--"
    , Other Phone : "--"
    , Email : ""
    , Sales Type : "Pre-Need"
    , Note 1 : "This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. This is Note 3. " 
    } 
]
, 1: [ 
    { Status : ""
    , Contact ID Number : "2"
    , Date Entered : "2011-07-02"
    , Date Assigned : "2011-07-02"
    , Date Last Modified : "2011-07-02"
    , Deceased Date : ""
    , Linked To Registrant 1 : "--"
    , Relationship 1 : "--"
    , Authorization 1 : "--"
    , Linked To Registrant 2 : "--"
    , Relationship 2 : "--"
    , Authorization 2 : "--"
    , Location : "Floral Haven Funeral Home "
    , Sales Manager : "Jayson Gordon"
    , Counselor : "Henry Murdoc"
    , Registration Number : "3"
    , Registration Date : "2003-12-02"
    , Program 1 Number : "4"
    , Program 1 Date : "2004-03-05"
    , Program 1 Name : "Non Registrant Test Program - Advantage"
    , Program 2 Number : "--"
    , Program 2 Date : "--"
    , Program 2 Name : "--"
    , First Name : "Leo"
    , Last Name : "Brown"
    , Address Location 1 : "home"
    , Address 1 : "5330 Ridge Rd "
    , City 1 : "Burlington"
    , State/Province 1 : "Ontario"
    , Zip/Postal Code 1 : "LVL7N9"
    , Home Phone : "9053919735"
    , Work Phone : "--"
    , Mobile Phone : "9057303737"
    , Pager : "--"
    , Other Phone : "--"
    , Email : "hmind@dont.com"
    , Sales Type : "PN to AN"
    , Note 1 : "This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. This is Note 5. " 
    } 
]
, 2: [ 
    { Status : "example1 status"
    , Contact ID Number : "3"
    , Date Entered : "2011-09-05"
    , Date Assigned : "2011-09-05"
    , Date Last Modified : "2011-09-05"
    , Deceased Date : ""
    , Linked To Registrant 1 : "Onelia Gary"
    , Relationship 1 : "Wife"
    , Authorization 1 : "1"
    , Linked To Registrant 2 : "--"
    , Relationship 2 : "--"
    , Authorization 2 : "--"
    , Location : "First Memorial Funeral Services"
    , Sales Manager : "Dan Thompson", Counselor : "Steve Brown"
    , Registration Number : "5"
    , Registration Date : "2010-11-11"
    , Program 1 Number : "7"
    , Program 1 Date : "2011-08-19"
    , Program 1 Name : "Non Registrant Test Program - Dignity"
    , Program 2 Number : "6"
    , Program 2 Date : "2011-07-03"
    , Program 2 Name : "Non Registrant Test Program - Advantage"
    , First Name : "Henry"
    , Last Name : "Murdoc"
    , Address Location 1 : "company"
    , Address 1 : "9055 Harvy Rd. 4"
    , City 1 : "Burlington"
    , State/Province 1 : "Ontario"
    , Zip/Postal Code 1 : "L7L5Z7"
    , Home Phone : "9055679602"
    , Work Phone : "9057455209"
    , Mobile Phone : "--"
    , Pager : "--"
    , Other Phone : "--"
    , Email : "pewter@live.com"
    , Sales Type : "At-Need"
    , Note 1 : "This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. This is Note 6. "
    } 
   ] 
}
Firebug报告此错误:

缺少:在属性id之后 …/view\u contacts\u search\u 1.php# 第188行

实例化变量时失败:

<script type='text/javascript' >
        $(document).ready(function(){ 
                var data = <?php echo($data)?>;

$(文档).ready(函数(){
var数据=;

你能找出缺少的元素是什么/在哪里吗?我已经试着找出这个问题好几个小时了,这让我很困惑。对于javascipt和jquery来说,新手也没有帮助:)

你的属性名称是数字的-这不是有效的JavaScript。请尝试重命名顶级属性或使它们成为字符串

这些都是有效的替代品:

{ 
    _0: [ ...

{ 
    number0: [ ...

{ 
    '0': [ ...
但老实说,最好是将属性名用字符串引起来,以避免类似的问题。

这样会更好:

{ 
"0": [ 
    { "Status" : "example status 2"
    , "Contact ID Number" : "1"
    , "Date Entered" : "2011-06-15"
    , ...

使用PHP内置的json转换函数,可以省去您的痛苦。

我可以将数字属性名转换为字符串吗?可以,然后其他大多数都是没有引号的多字字符串。现在尝试解决这个问题。看看这是否也是问题的一部分吗?谢谢!实际上,使用数字l对象文本中属性名的iteral(例如,
{0:“foo”}
)是完全有效的,请参见。它非常清楚地表明PropertyName部分(左侧)属性初始值设定项的名称必须是IdentifierName、StringLiteral或NumericLiteral。问题是Tomalak指出的其他标识符无效。同意通常最好对属性名称使用字符串文字,因此您不必担心标识符名称的规则。是的,使用数字文本它确实发布了数据,并在转义双字后消除了错误。PHP json_encode没有正确编码数据。我尝试使用它,但它将[Object Object,Object Object Object,Object Object Object]作为字符串。我知道这是一个字符串,因为当运行json_解码时,生成的变量是string类型。bummer:(json_编码不起作用一定有原因,编写自己的json序列化程序并不是解决这个问题的办法。是的,我相信你是对的;尽管我现在的json_编码起作用了,而php没有?!