正在获取JSON html数据



我正在从wordpress数据库中获取JSON数据,以便使用android studio将其添加到移动应用程序中。然而,我面临着许多问题。首先,我需要正确查看帖子内容,但html标签呢?在搜索之后,我将JSON_HEX_TAG|JSON_PRETTY_PRINT|JSON_HEX _QUO|JSON-HEX_AMP|JSON_UNESCAPED_UNCODE添加到我的输出中,但这并没有解决我的问题。=

PHP代码

<?php 
header('content-type: application/json; charset=utf-8');
/*
* Created by Belal Khan
* website: www.simplifiedcoding.net 
* Retrieve Data From MySQL Database in Android
*/

//database constants
define('DB_HOST', 'localhost');
define('DB_USER', '');
define('DB_PASS', '');
define('DB_NAME', '');

//connecting to database and getting the connection object
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}


function getAttachment($post_title) {

$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$stmt = $conn->prepare("SELECT guid,post_title  FROM wp_posts  WHERE `post_type`='attachment'  AND `post_title` = ?");
$conn -> set_charset("utf8");
$stmt->bind_param("s",$post_title);
$stmt->execute();
$stmt->store_result();    
$stmt->bind_result($guid, $post_title); 
$products_attach = array(); 
if($stmt->num_rows == 1) {
while($stmt->fetch()){
$temp = array();
$temp['guid'] = $guid; 

array_push($products_attach, $temp);
}
return     $temp['guid'];
}
}






//creating a query
$stmt = $conn->prepare("SELECT ID, post_title, post_content  FROM wp_posts  WHERE `post_type`='lsvr_document'AND `post_status`= 'publish';");
$conn -> set_charset("utf8");
//executing the query 
$stmt->execute();

//binding results to the query 
$stmt->bind_result($id, $title, $content);

$products = array(); 

//traversing through all the result 
while($stmt->fetch()){
$temp = array();
$temp['id'] = $id; 
$temp['title'] = $title; 
$temp['link'] = getAttachment($temp['title']);
$temp['content'] = $content; 

array_push($products, $temp);
}

//displaying the result in json format 
//  echo json_encode($products, JSON_UNESCAPED_UNICODE  | JSON_HEX_TAG );

$json = json_encode($products, JSON_HEX_TAG | JSON_PRETTY_PRINT  | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
echo $json;
//print_r($products);

?>

一些输出

"id": 867,
"title": "إفادة إنجاز بناء مخالف",
"link": "http://syncsecser.com/municipal/wp-content/uploads/2020/09/إفادة-إنجاز-بناء-مخالف.pdf",
"content": "u003C!-- wp:heading --u003Enu003Ch2u003Eالمستندات المرفقة و أماكن إنجازهاu003C/h2u003Enu003C!-- /wp:heading --u003Ennu003C!-- wp:paragraph --u003Enu003Cpu003E1. طلب موقع من صاحب العلاقة أو من ينوب عنه قانوناً.u003Cbru003E2. إفادة عقاريةu0026nbsp;شاملة.u003Cbru003E3. أي مستند يثبت تاريخ إنجاز المخالفة.u003C/pu003Enu003C!-- /wp:paragraph --u003Ennu003C!-- wp:table {u0022classNameu0022:u0022is-style-regularu0022} --u003Enu003Cfigure id=u0022table1u0022 class=u0022wp-block-table is-style-regularu0022u003Eu003Ctableu003Eu003Ctbodyu003Eu003Ctru003Eu003Ctdu003Eu003Cbru003Eu003Cbru003E-u003Cstrongu003Eu003Cuu003Eمدّةu0026nbsp;الإنجاز :u003C/uu003Eu003C/strongu003Eu003Cbru003Eu0026nbsp;ثلاثة أيام سنداًu0026nbsp;لتعميم وزير الداخلية والشؤون البلدية والقروية رقم 8/99.u003Cbru003Eu003Cbru003E-u003Cstrongu003Eu0026nbsp;الرسومu0026nbsp;المتوجبةu003Cbru003Eu003Cbru003Eu0026nbsp;u003C/strongu003Eu003Cbru003E1.u0026nbsp;u0026nbsp;رسم الإفادة الفنية:u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp; 2000 ل.ل.u003Cbru003Eu0026nbsp;u003Cbru003E2.u0026nbsp;u0026nbsp;رسم طابع مالي:u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;u0026nbsp;1000 ل.ل.u003Cbru003Eu003C/tdu003Eu003C/tru003Eu003C/tbodyu003Eu003C/tableu003Eu003C/figureu003Enu003C!-- /wp:table --u003E"
},

一个简单的解决方案是,您可以将内容编码为base64,然后在您的移动应用程序或任何其他想要解析内容的页面中,只需解码此base64即可。

相关内容

  • 没有找到相关文章

最新更新