Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
Javascript JSON.parse值是单个字符吗?_Javascript_Jquery_Json - Fatal编程技术网

Javascript JSON.parse值是单个字符吗?

Javascript JSON.parse值是单个字符吗?,javascript,jquery,json,Javascript,Jquery,Json,为什么我要让每个单独的字符显示为一个类似于0的值:{ memory=to; var store='['; $.each($('.spoke'),function(){ store=store+'"'+$(this).attr('id')+'":"'+hexEncode('<div class="spoke"from="'+$(this).attr('from')+'"id="'+$(this).attr('id')+'">'+$(this).htm

为什么我要让每个单独的字符显示为一个类似于0的值:{

    memory=to;
    var store='[';


    $.each($('.spoke'),function(){
    store=store+'"'+$(this).attr('id')+'":"'+hexEncode('<div class="spoke"from="'+$(this).attr('from')+'"id="'+$(this).attr('id')+'">'+$(this).html()+'</div>')+'",';
    });


    store=store+']';store=store.replace(',]',']');





    $.localStorage.setItem(memory,JSON.stringify(store));

    var posts=$.localStorage.getItem(memory);

    posts=JSON.parse(posts);

    alert(posts);

    $.each(posts, function(key, value){

    alert(key+' : '+value);
    });
memory=to;
变量存储='[';
$.each($('.spoke'),function(){
store=store+'“'+$(this.attr('id')+'”:“'+hexEncode('+$(this.html()++'))+”,”;
});
store=store+']';store=store.replace(',]',']');
$.localStorage.setItem(内存,JSON.stringify(存储));
var posts=$.localStorage.getItem(内存);
posts=JSON.parse(posts);
警报(员额);
$。每个(帖子、功能(键、值){
警报(键+':'+值);
});
-------------------------哇,我太累了3点15分修好了

function save(){
    memory=to;
    var store={};


    $.each($('.spoke'),function(){
    var id=$(this).attr('id');

    var p=hexEncode('<div class="spoke"from="'+$(this).attr('from')+'"id="'+$(this).attr('id')+'">'+$(this).html()+'</div>');
    store[id]=p;
    });

    $.localStorage.setItem(memory,JSON.stringify(store));

    var posts=$.localStorage.getItem(memory);

    posts=JSON.parse(posts);


    $.each(posts, function(key, value){
    $('#log').append(hexDecode(value)+' it works');
    //$.each(value, function(key, value){
    //$('#log').append(value+' it works2');
    });//});
函数保存(){
内存=到;
var-store={};
$.each($('.spoke'),function(){
var id=$(this.attr('id');
var p=hexEncode(“”+$(this.html()+“”);
存储[id]=p;
});
$.localStorage.setItem(内存,JSON.stringify(存储));
var posts=$.localStorage.getItem(内存);
posts=JSON.parse(posts);
$。每个(帖子、功能(键、值){
$('#log').append(hexDecode(value)+“it works”);
//$.each(值、函数(键、值){
//$('#log').append(value+'it works2');
});//});

您已经对字符串进行了字符串化,因此当您解析它时,您将返回一个字符串,并且您将只读取字符串中特定索引处的字符。而不是尝试手动构建JSON,而是构建一个数组或对象,然后对其进行字符串化。

您不是在生成一个数组,而是一个可解析为数组的字符串。您还正在关闭tes(“),然后结束元素。您可以创建有效字符串或有效数组

store = [];
store.push("whatever");
$.localStorage.setItem(memory,JSON.stringify(store));

通过更改:$.localStorage.setItem(memory,store);//$.localStorage.setItem(memory,JSON.stringify(store)),我得到了一个错误:未捕获的语法错误:意外标记:为什么要将其更改为该标记?