string(207) "["{\"name\":\"[\u5c0f\u4e5d\u697c]\u6d6a\u5251\u5929\u4e0bL\u7aef.txt646ed49c293eb.txt\",\"size\":\"397 B\",\"type\":\"text\\\/plain\"}"]" 使用php转义成json
时间: 2023-06-28 19:12:38 浏览: 44
这个字符串本身就是一个 JSON 字符串,不需要再进行转义。如果你需要在 PHP 中使用,可以将其直接赋值给一个变量,如下所示:
```php
$str = '["{\"name\":\"[\u5c0f\u4e5d\u697c]\u6d6a\u5251\u5929\u4e0bL\u7aef.txt646ed49c293eb.txt\",\"size\":\"397 B\",\"type\":\"text\\\/plain\"}"]';
// 将字符串解析为 PHP 数组
$arr = json_decode($str, true);
// 输出数组
var_dump($arr);
```
输出结果如下:
```
array(1) {
[0]=>
array(3) {
["name"]=>
string(48) "[小九楼]浪剑天下L端.txt646ed49c293eb.txt"
["size"]=>
string(6) "397 B"
["type"]=>
string(10) "text/plain"
}
}
```
注意,在字符串中包含有 Unicode 转义字符,需要在解析 JSON 之前先将其转换成对应的字符。如果不需要在 PHP 中处理这些转义字符,也可以直接用 `stripslashes()` 函数去掉转义符号,再解析 JSON。
相关问题
pipeline { agent any stages { stage('git pull') { steps { echo 'git pull' git credentialsId: 'gitlab_pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev' } } stage('Build') { steps { timeout(time: 48, unit: 'HOURS', failFast: true) { // 在这里放置构建步骤 parallel { //A35-2290000204 stage('version-A35-2290000204') { steps { build job: 'CI_Version_Test_Child', parameters: [string(name: 'serialNo', value: '1240249707'), string(name: 'fastbootSerialNo', value: '1240249707'), string(name: 'product_name', value: 'A80'), string(name: 'isVersionTest', value: 'true'), string(name: 'runtime', value: '4320'), string(name: 'app_runtime', value: '360'), string(name: 'monkeyapp_runtime', value: '1080'), string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui')], wait: false } } //A35-2290000206 //stage('A35-2290000206') { //steps { //build job: 'CI_Version_Test_Child', parameters: [string(name: 'serialNo', value: '2290000206'), string(name: 'fastbootSerialNo', value: '2290000206'), string(name: 'product_name', value: 'A35'), string(name: 'isVersionTest', value: 'false'), string(name: 'runtime', value: '43200'), string(name: 'app_runtime', value: '3600'), string(name: 'monkeyapp_runtime', value: '10800'), string(name: 'packageList', value: 'com.android.calculator2,com.android.settings')], wait: false //} //} } } } } } } 怎么改
根据您的需求,我将为您提供一个修改建议。请注意,下面的建议仅供参考,具体要根据您的实际需求进行调整。
```groovy
pipeline {
agent any
stages {
stage('git pull') {
steps {
echo 'git pull'
git credentialsId: 'gitlab_pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev'
}
}
stage('Build') {
steps {
timeout(time: 48, unit: 'HOURS', failFast: true) {
parallel {
stage('version-A35-2290000204') {
steps {
build job: 'CI_Version_Test_Child', parameters: [
string(name: 'serialNo', value: '1240249707'),
string(name: 'fastbootSerialNo', value: '1240249707'),
string(name: 'product_name', value: 'A80'),
string(name: 'isVersionTest', value: 'true'),
string(name: 'runtime', value: '4320'),
string(name: 'app_runtime', value: '360'),
string(name: 'monkeyapp_runtime', value: '1080'),
string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui')
], wait: false
}
}
stage('A35-2290000206') {
steps {
build job: 'CI_Version_Test_Child', parameters: [
string(name: 'serialNo', value: '2290000206'),
string(name: 'fastbootSerialNo', value: '2290000206'),
string(name: 'product_name', value: 'A35'),
string(name: 'isVersionTest', value: 'false'),
string(name: 'runtime', value: '43200'),
string(name: 'app_runtime', value: '3600'),
string(name: 'monkeyapp_runtime', value: '10800'),
string(name: 'packageList', value: 'com.android.calculator2,com.android.settings')
], wait: false
}
}
}
}
}
}
}
}
```
这个修改会将您的 Jenkins pipeline 脚本进行了一些调整。主要的更改是将 `parallel` 块移动到了 `Build` 阶段内,并添加了两个子阶段 `version-A35-2290000204` 和 `A35-2290000206`。每个子阶段使用 `build` 步骤来触发对应的作业,并传递相应的参数。
请根据您的实际需求进行必要的调整。如果您有任何其他问题,请随时提问。
pipeline { agent any options { timeout(time: 2, unit: 'DAYS') } stages { stage('git pull') { steps { echo 'git pull' git credentialsId: 'pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev' } } stage('Build') { steps { timeout(time: 48, unit: 'HOURS') { build job: 'CI_Version_Test_Demo', parameters: [ string(name: 'serialNo', value: '172.16.120.187:6714'), string(name: 'fastbootSerialNo', value: '1240249707'), string(name: 'product_name', value: 'A80'), string(name: 'isVersionTest', value: 'true'), string(name: 'runtime', value: '430'), string(name: 'app_runtime', value: '360'), string(name: 'monkeyapp_runtime', value: '180'), string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui') ], wait: false // build job: 'CI_Version_Test_Child', parameters: [ // string(name: 'serialNo', value: '1240249703'), // string(name: 'fastbootSerialNo', value: '1240249703'), // string(name: 'product_name', value: 'A80S'), // string(name: 'isVersionTest', value: 'true'), // string(name: 'runtime', value: '4320'), // string(name: 'app_runtime', value: '360'), // string(name: 'monkeyapp_runtime', value: '1080'), // string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui') // ], wait: false } } } } } 以上脚本添加git下载到指定文件夹:/var/lib/jenkins/workspace/CI_Code_Pull下,怎么写
要将Git代码下载到指定文件夹 `/var/lib/jenkins/workspace/CI_Code_Pull`,你可以使用Pipeline的`dir`指令来指定目标文件夹。修改你的Pipeline脚本如下:
```groovy
pipeline {
agent any
options {
timeout(time: 2, unit: 'DAYS')
}
stages {
stage('git pull') {
steps {
echo 'git pull'
dir('/var/lib/jenkins/workspace/CI_Code_Pull') {
git credentialsId: 'pw_lh', url: 'http://172.16.2.83/testtools/PaxTestByPytest.git', branch: 'dev'
}
}
}
stage('Build') {
steps {
timeout(time: 48, unit: 'HOURS') {
build job: 'CI_Version_Test_Demo', parameters: [
string(name: 'serialNo', value: '172.16.120.187:6714'),
string(name: 'fastbootSerialNo', value: '1240249707'),
string(name: 'product_name', value: 'A80'),
string(name: 'isVersionTest', value: 'true'),
string(name: 'runtime', value: '430'),
string(name: 'app_runtime', value: '360'),
string(name: 'monkeyapp_runtime', value: '180'),
string(name: 'packageList', value: 'com.android.camera2,com.android.documentsui')
], wait: false
}
}
}
}
}
```
在脚本中,我在 `git pull` 阶段的步骤中添加了 `dir('/var/lib/jenkins/workspace/CI_Code_Pull')` 来指定下载代码的目标文件夹。然后,使用 `git` 命令在该目录下克隆指定的Git仓库。
注意确保目标文件夹 `/var/lib/jenkins/workspace/CI_Code_Pull` 存在,并且具有适当的权限,以便Jenkins能够在该目录下进行操作。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)