Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
php Json删除键的双引号以及如何更改键的名称_Php_Json - Fatal编程技术网

php Json删除键的双引号以及如何更改键的名称

php Json删除键的双引号以及如何更改键的名称,php,json,Php,Json,示例Json data:[{"varExchange":"ftx","varPrice":482.3},{"varExchange":"ftx","varPrice":481.8}] 我想将密钥的名称从“varExchange”更改为“name”,将“varPrice”更改为“qty” 我需要删除键的双引号 输出类 data:[{name:"test","qty":482.3},{name:"test","qty":481.8}] 请帮我解决这个问题。 谢谢首先输入正确的json数组 然后

示例Json

data:[{"varExchange":"ftx","varPrice":482.3},{"varExchange":"ftx","varPrice":481.8}]
  • 我想将密钥的名称从“varExchange”更改为“name”,将“varPrice”更改为“qty”
  • 我需要删除键的双引号
  • 输出类

     data:[{name:"test","qty":482.3},{name:"test","qty":481.8}]
    
    请帮我解决这个问题。
    谢谢

    首先输入正确的json数组

    然后根据您更改密钥的需要创建新数组

    var数据=[{“varExchange”:“ftx”,“varPrice”:482.3},{“varExchange”:“ftx”,“varPrice”:481.8}];
    var新_数据=[];
    for(数据中的var k){
    new_data.push({name:data[k].varExchange,qty:data[k].varPrice});
    }
    
    console.log(新的_数据)我认为这很简单

  • 只需使用JSON.stringify()将JSON对象转换为字符串
  • 将子字符串,即“varExchange”替换为名称,“varPrice”替换为数量

  • 同样,您可以将其强制转换为对象。

    什么是
    数据:[
    ??