wmaraci reklam
lidertakipci

Php json_encode tırnak problemi

7 Mesajlar 2.790 Okunma
advertseo
wmaraci reklam

olkunmustafa olkunmustafa WM Aracı Kullanıcı
  • Üyelik 18.04.2012
  • Yaş/Cinsiyet 36 / E
  • Meslek Web & Android Developer
  • Konum
  • Ad Soyad M** O**
  • Mesajlar 423
  • Beğeniler 60 / 44
  • Ticaret 0, (%0)
Merhabalar.

Siteme webservis yazmaya çalışıyorum. Mysql verileri dizi halinde çekip json_encode ile çevirmeye çalıştığımda post_content satırında link,img gibi html kodları olduğu zaman çıktı aşağıdaki gibi oluyor.



Gördüğünüz gibi düzgün görüntülenemiyyor. Kodlarım aşağıdaki gibidir.

public function get_posts($status=false) {
$sql = "select * from wp_posts where post_status='publish' and post_type='post' order by ID DESC limit 0,1";
$query = mysql_query($sql);
$posts = array();
while ($result = mysql_fetch_assoc($query)):
$this->posts[] = array("posts" => $result["post_content"]);
endwhile;
}

public function get_json() {
$this->get_posts();
header('Content-type: application/json');
echo json_encode(array('posts' => $this->posts));
}


Sitem wordpress bir sistem. Tüm sitenin webservisini json formatında verebilecek başka bir sistem varsa da fikirleri alabilirim
 

 

wmaraci
reklam

cudjex cudjex ozergul.net Kullanıcı
  • Üyelik 23.11.2011
  • Yaş/Cinsiyet 31 / E
  • Meslek öğrenci
  • Konum İzmir
  • Ad Soyad Ö** G**
  • Mesajlar 1647
  • Beğeniler 347 / 570
  • Ticaret 8, (%100)
// include our wordpress functions
// change relative path to find your WP dir
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');

// set header for json mime type
header('Content-type: application/json;');

// get latest single post
// exclude a category (#5)
query_posts(array(
'posts_per_page' => 1,
'cat' => -5,
));

$jsonpost = array();
if (have_posts()) {
// initialize functions used below
the_post();

// construct our array for json
// apply_filters to content to process shortcodes, etc
$jsonpost["id"] = get_the_ID();
$jsonpost["title"] = get_the_title();
$jsonpost["url"] = apply_filters('the_permalink', get_permalink());
$jsonpost["content"] = apply_filters('the_content', get_the_content());

// would rather do iso 8601, but not supported in gwt (yet)
$jsonpost["date"] = get_the_time('d F Y');

} else {
// deal with no posts returned
}

// output json to file
echo json_encode($jsonpost);
?>


link.
 

 

ozergul.net/com

olkunmustafa olkunmustafa WM Aracı Kullanıcı
  • Üyelik 18.04.2012
  • Yaş/Cinsiyet 36 / E
  • Meslek Web & Android Developer
  • Konum
  • Ad Soyad M** O**
  • Mesajlar 423
  • Beğeniler 60 / 44
  • Ticaret 0, (%0)

cudjex adlı üyeden alıntı

// include our wordpress functions
// change relative path to find your WP dir
define('WP_USE_THEMES', false);
require('./blog/wp-blog-header.php');

// set header for json mime type
header('Content-type: application/json;');

// get latest single post
// exclude a category (#5)
query_posts(array(
'posts_per_page' => 1,
'cat' => -5,
));

$jsonpost = array();
if (have_posts()) {
// initialize functions used below
the_post();

// construct our array for json
// apply_filters to content to process shortcodes, etc
$jsonpost["id"] = get_the_ID();
$jsonpost["title"] = get_the_title();
$jsonpost["url"] = apply_filters('the_permalink', get_permalink());
$jsonpost["content"] = apply_filters('the_content', get_the_content());

// would rather do iso 8601, but not supported in gwt (yet)
$jsonpost["date"] = get_the_time('d F Y');

} else {
// deal with no posts returned
}

// output json to file
echo json_encode($jsonpost);
?>


link.


BU şekilde json verisi aldığımız zaman nereye bastırıyoruz peki ?
 

 

fatihuzuner fatihuzuner WM Aracı Kullanıcı
  • Üyelik 19.03.2013
  • Yaş/Cinsiyet 34 / E
  • Meslek bilgisayar mühendisi
  • Konum İstanbul Anadolu
  • Ad Soyad ** **
  • Mesajlar 86
  • Beğeniler 2 / 13
  • Ticaret 0, (%0)
hangi sayfada ise oraya :D bu arada btsoru.comda bu soruyu soran sen miydin :D
 

 

wmaraci
wmaraci

AUNSAL AUNSAL Facebook Api Developer Kullanıcı
  • Üyelik 06.01.2012
  • Yaş/Cinsiyet - / E
  • Meslek
  • Konum
  • Ad Soyad ** **
  • Mesajlar 44
  • Beğeniler 1 / 12
  • Ticaret 0, (%0)
Sanırım probleminiz slash karakteri

stripslashes();

fonksiyonunu inceleyiniz.
 

 

olkunmustafa olkunmustafa WM Aracı Kullanıcı
  • Üyelik 18.04.2012
  • Yaş/Cinsiyet 36 / E
  • Meslek Web & Android Developer
  • Konum
  • Ad Soyad M** O**
  • Mesajlar 423
  • Beğeniler 60 / 44
  • Ticaret 0, (%0)

fatihuzuner adlı üyeden alıntı

hangi sayfada ise oraya :D bu arada btsoru.comda bu soruyu soran sen miydin :D


Evet bendim :D
Hangi sayfaysa oraya dediğiniz bir wordpress sayfası oluşturup orayı mı kullanacağım. Ama bu sefer de sayfaya html kodları bastırıp hata verdirmez mi ?

Şu anki sorunumu çözdüm aslında ama bu yöntem daha pratik görünüyor. Ancak sayfayı bastırmak bence problem olabilir.

A ÜNSAL adlı üyeden alıntı

Sanırım probleminiz slash karakteri

stripslashes();

fonksiyonunu inceleyiniz.


Stripslashes dediğim zaman NULL atıyordur. Sorun aslında header() fonksiyonundaymış. Sayfadaki tüm html kodlarını temizledim soru çözüldü şimdilik.
 

 

fatihuzuner fatihuzuner WM Aracı Kullanıcı
  • Üyelik 19.03.2013
  • Yaş/Cinsiyet 34 / E
  • Meslek bilgisayar mühendisi
  • Konum İstanbul Anadolu
  • Ad Soyad ** **
  • Mesajlar 86
  • Beğeniler 2 / 13
  • Ticaret 0, (%0)
zaten bu json verilerini ajax ile işle. ajax json çıktısının olacağı sayfaya istekte bulunsun. gelen verileri javascript ile gerekli yere doldurtursun. en temizi bu.
 

 

wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al