//JSON 声明
var jsonDECL = {"name": "小明", "age": 12};

//字符串转JSON
function Json_StringToString(json){
    var result = "";
    try{
        result = Json.stringify(json);
    }catch(e){
        result = json;
    }
    return result;
}

//JSON转字符串1
function Json_StringToJson_ByParse(jsonStr){
    var json ;
    try{
        json = JSON.parse(jsonStr);
        //json =  $.parseJSON( jsonStr); //两种方式类似
    }catch(e){
        json = null;
    }
    return json;
}

//JSON转字符串2
function Json_StringToJson_ByEval(jsonStr){
    var json ;
    try{
        json =  eval("(" + jsonStr + ")");
    }catch(e){
        json = null;
    }
    return json;
}


//JSON转字符串3 未写完
function Json_StringToJson_By3(){
    var json ;
    try{
        json = JSON.parse(str);
    }catch(e){
        json = null;
    }
    return json;
}


//JSON取值
function Json_GetData(json,value){
    return json.value;
    //return json[value];
}

//Json 判断属性是否存在
function Json_hasOwnProperty(json,id){
    return json.hasOwnProperty(id);
}

/*<script type='text/javascript' src="/jquery.js"></script>
    <script type="text/javascript">
    $().ready(
        function(){
            var array = [1,2,3,4,5,6,7,8,9];
            var filterarray = $.grep(array,function(value){
                return value > 5;//筛选出大于5的
            });
            for(var i=0;i<filterarray.length;i++){
                alert(filterarray[i]);
            }
            for (key in filterarray){
                alert(filterarray[key]);
            }
        }
    );
</script>*/

/*<script type='text/javascript' src="/jquery.js"></script>
    <script type="text/javascript">
    $().ready(
        function(){
            var anObject = {one:1,two:2,three:3};//对json数组each
            $.each(anObject,function(name,value) {
                alert(name);
                alert(value);
            });
            var anArray = ['one','two','three'];
            $.each(anArray,function(n,value){
                    alert(n);
                    alert(value);
                }
            );
        }
    );
</script>*/

/*
<script type='text/javascript' src="/jquery.js"></script>
    <script type="text/javascript">
    $().ready(
        function(){
            var anArray = ['one','two','three'];
            var index = $.inArray('two',anArray);
            alert(index);//返回该值在数组中的键值，返回1
            alert(anArray[index]);//value is two
        }
    );
</script>*/

/*
<script type='text/javascript' src="/jquery.js"></script>
    <script type="text/javascript">
    $().ready(
        function(){
            var strings = ['0','1','2','3','4','S','6'];
            var values = $.map(strings,function(value){
                    var result = new Number(value);
                    return isNaN(result) ? null:result;//isNaN:is Not a Number的缩写
                }
            );
            for (key in values) {
                alert(values[key]);
            }
        }
    );
</script>*/

/*<script>
var json = [{dd:'SB',AA:'东东',re1:123},{cccc:'dd',lk:'1qw'}];
for(var i=0,l=json.length;i<l;i++){
    for(var key in json[i]){
        alert(key+':'+json[i][key]);
    }
}
</script>*/


/*
packJson = [

    {"name":"nikita", "password":"1111"},

    {"name":"tony", "password":"2222"}

];

for(var p in packJson){//遍历json数组时，这么写p为索引，0,1

    alert(packJson[p].name + " " + packJson[p].password);

}*/

/*myJson = {"name":"caibaojian", "password":"1111"};

for(var p in myJson){//遍历json对象的每个key/value对,p为key

    alert(p + " " + myJson[p]);

}*/
