我正在从API URL中提取JSON数据。我需要提取特定的KEYS并将它们放入具有列和行的表中。 6(col)x 20+(行)。密钥彼此都是重复的(值,内容):
{
"response": {
"result": {
"Leads": {
"row": [
{
"no": "1",
"FL": [
{
"val": "LEADID",
"content": "123"
},
{
"val": "SMOWNERID",
"content": "3232"
},
{
"val": "Lead Owner",
"content": "Cassie"
},
{
"val": "First Name",
"content": "Bobby"
},
{
"val": "Last Name",
"content": "Something"
},
{
"val": "Email",
"content": "email@gmail.com"
},
{
"val": "Mobile",
"content": "1111111111"
},
{
"val": "SMCREATORID",
"content": "0000003213"
},
{
"val": "Created By",
"content": "Cassie"
},
{
"val": "Created Time",
"content": "2019-04-03 15:14:05"
},
{
"val": "Modified Time",
"content": "2019-04-03 17:13:58"
},
{
"val": "Full Name",
"content": "Bobby Something"
},
{
"val": "Street",
"content": "123 Fake Rd"
},
{
"val": "City",
"content": "Fakecity"
},
{
"val": "State",
"content": "FK"
},
{
"val": "Zip Code",
"content": "11111"
},
{
"val": "Email Opt Out",
"content": "false"
},
{
"val": "Salutation",
"content": "Mr."
},
{
"val": "Last Activity Time",
"content": "2019-04-03 17:13:58"
},
{
"val": "Tag",
"content": "Tag"
},
{
"val": "Account Name",
"content": "Something"
},
{
"val": "Territory Manager",
"content": "Michael Something"
},
{
"val": "Territory Manager_ID",
"content": "321237000000291111"
},
{
"val": "Classification",
"content": "Something"
},
{
"val": "Area",
"content": "Zone 1"
},
{
"val": "Account Number",
"content": "32345"
}
]
}
]
}
},
"uri": "/crm/private/json/Leads/getRecords"
}
}
<?php
$url = 'URL';
$data = file_get_contents($url);
$parsed = json_decode($data, true);
$eachEntry = $parsed['response']['result']['Leads']['row'];
$valuesIWant = ["First Name", "Last Name", "Street", "City", "State", "Zip Code"];
echo '<table class="uabb-table-inner-wrap">';
echo '<thead class="uabb-table-header"><tr class="table-header-tr">
<th class="table-header-th">First Name</th><th class="table-header-th">Last Name</th><th class="table-header-th">Street</th><th class="table-header-th">City</th><th>State</th><th class="table-header-th">Zip Code</th>
</tr></thead>';
foreach ($eachEntry as $entry) {
$FL = $entry['no'];
//printf("\n");
$entries = $entry['FL'];
echo '<tbody class="uabb-table-features"><tr class="tbody-row">';
foreach ($entries as $value) {
$val = $value['val'];
$content = $value['content'];
if (in_array($val, $valuesIWant)) {
//$out = $val;
$out2 = $content;
//echo '<td>'. $out .'</td>';
echo '<td class="table-body-td">'. $out2 .'</td>';
}
}
echo '</tr></tbody>';
}
echo '</table>';
?>
我正在尝试输出为表结构:
这是来自PHP JSON Decoding To Array To Grab Specific Key Values (All fields same name)
的扩展问题<style>
.uabb-table {
overflow-x: auto;
margin-left: auto;
margin-right: auto;
zoom: 1;
display: flex;
}
.uabb-table .uabb-table-element-box {
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
-webkit-box-flex: 1;
flex-grow: 1;
}
.uabb-table .uabb-table-wrapper {
text-align: center;
position: relative;
height: 100%;
}
.uabb-table-inner-wrap {
width: 100%;
}
.fl-module-uabb-table .uabb-table-wrapper .uabb-table-inner-wrap {
border-collapse: collapse;
margin: 0;
}
.uabb-table .uabb-table-wrapper {
text-align: center;
position: relative;
}
.fl-module-uabb-table .uabb-table-wrapper .uabb-table-inner-wrap {
border-collapse: collapse;
margin: 0;
}
.uabb-table-inner-wrap .uabb-table-header .table-header-th {
border: 1px solid #000000;
padding: 15px;
}
.uabb-table .uabb-table-header .table-header-th {
overflow-wrap: normal;
}
.uabb-table .uabb-table-header .table-header-th, .uabb-table .uabb-table-features .table-body-td {
vertical-align: middle;
padding: 15px;
border: 1px solid #000000;
}
.uabb-table .uabb-table-header .table-header-tr .table-header-th .th-style .head-inner-text, .uabb-table .uabb-table-header .table-header-tr .table-header-th .th-style {
background: none;
}
.uabb-table .table-header-th .th-style {
padding-right: 15px;
}
label {
display: inline-block;
margin-bottom: .5rem;
}
.uabb-table .uabb-table-header .table-header-tr .table-header-th .th-style .head-inner-text, .uabb-table .uabb-table-header .table-header-tr .table-header-th .th-style {
background: none;
}
.content-text {text-transform: uppercase;}
</style>
<?php
$url = 'URL';
$data = file_get_contents($url);
$parsed = json_decode($data, true);
$eachEntry = $parsed['response']['result']['Leads']['row'];
$valuesIWant = ["First Name", "Last Name", "Street", "City", "State", "Zip Code"];
echo '<div class="uabb-table-module-content uabb-table">
<div class="uabb-table-element-box">
<div class="uabb-table-wrapper">
<table class="uabb-table-inner-wrap">
<thead class="uabb-table-header">
<tr class="table-header-tr">
<th class="table-heading-0 table-header-th" rowspan="" colspan="">
<label class="head-style-0 th-style">
<label class="head-inner-text">First Name</label>
</label>
</th>
<th class="table-heading-1 table-header-th" rowspan="" colspan="">
<label class="head-style-1 th-style">
<label class="head-inner-text">Last Name</label>
</label>
</th>
<th class="table-heading-2 table-header-th" rowspan="" colspan="">
<label class="head-style-2 th-style">
<label class="head-inner-text">Street</label>
</label>
</th>
<th class="table-heading-3 table-header-th" rowspan="" colspan="">
<label class="head-style-3 th-style">
<label class="head-inner-text">City</label>
</label>
</th>
<th class="table-heading-4 table-header-th" rowspan="" colspan="">
<label class="head-style-4 th-style">
<label class="head-inner-text">State</label>
</label>
</th>
<th class="table-heading-5 table-header-th" rowspan="" colspan="">
<label class="head-style-5 th-style">
<label class="head-inner-text">Zip Code</label>
</label>
</th>
</tr>
</thead>';
foreach ($eachEntry as $entry) {
$FL = $entry['no'];
//printf("\n");
$entries = $entry['FL'];
echo '<tbody class="uabb-table-features"><tr class="tbody-row">';
foreach ($entries as $value) {
$val = $value['val'];
$content = $value['content'];
if (in_array($val, $valuesIWant)) {
//$out = $val;
$out2 = $content;
//echo '<td>'. $out .'</td>';
echo '<td class="table-body-td table-body-0" colspan="" rowspan=""><span class="content-text">'. $out2 .'</span></td>';
}
}
echo '</tr></tbody>';
}
echo '</table></div></div></div>';
?>
答案 0 :(得分:0)
我解决了这个问题:
=IF(OR(LEFT(A2,1)=\"=\",LEFT(A2,1)=\"+\"),\"'\"&A2,A2)