3

我有一个json字符串,我想通过 php url 在 extjs 的网格存储中获取它。如何从 php 文件中将此字符串作为 json 返回。像这样的东西:

var store = Ext.create('Ext.data.Store', {
    id: 'store',
    model: 'ForumThread',
    remoteGroup: true,
    buffered: true,
    leadingBufferZone: 300,
    pageSize: 100,
    proxy: {
        type: 'jsonp',
        url: 'myJsonPhp.php', //this file should return json.
        reader: {
            root: 'topics',
            totalProperty: 'totalCount'
        }},
    autoLoad: true
});

我知道有从 php 返回 json 的方法,但是它们创建然后返回 json。我已经有json ..

* JSON 字符串:*

{"totalCount":"6679","topics":[{"title":"XTemplate with in EditorGridPanel","threadid":"133690","username":"kpr@emco","userid":"272497","dateline":"1305604761","postid":"602876","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"2","lastpost":"1305857807","excerpt":""},{"title":"IFrame error "_flyweights is undefined"","threadid":"133571","username":"Daz","userid":"52119","dateline":"1305533577","postid":"602456","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"1","lastpost":"1305857313","excerpt":""},{"title":"Status bar error with IFrames","threadid":"134120","username":"Daz","userid":"52119","dateline":"1305857168","postid":"604220","forumtitle":"Ext 3.x: Bugs","forumid":"41","replycount":"0","lastpost":"1305857168","excerpt":""},{"title":"hellllllllllllllp,why it doesn't fire cellclick event after I change the cell value??","threadid":"133827","username":"aimer311","userid":"162000","dateline":"1305700219","postid":"603309","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"3","lastpost":"1305856996","excerpt":""},{"title":"Extjs 4.0 support for IE9","threadid":"122352","username":"extdev22","userid":"48017","dateline":"1296097557","postid":"565503","forumtitle":"Ext: Open Discussion","forumid":"6","replycount":"30","lastpost":"1305841535","excerpt":""},{"title":"Using XTemplate to send XML","threadid":"134102","username":"cayenne_08","userid":"237393","dateline":"1305841170","postid":"604153","forumtitle":"Ext 3.x: Help","forumid":"40","replycount":"0","lastpost":"1305841170","excerpt":""},{"title":"Open Source Development - The people you interact with....","threadid":"134093","username":"watrboy00","userid":"9862","dateline":"1305837814","postid":"604114","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837814","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134091","username":"Andrew.Golik","userid":"32056","dateline":"1305837033","postid":"604102","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305837033","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134090","username":"Andrew.Golik","userid":"32056","dateline":"1305836975","postid":"604100","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836975","excerpt":""},{"title":"What widgets are missing most in the ExtJs library?","threadid":"134089","username":"Andrew.Golik","userid":"32056","dateline":"1305836900","postid":"604099","forumtitle":"Community Discussion","forumid":"68","replycount":"0","lastpost":"1305836900","excerpt":""}]}
4

1 回答 1

2

最简单的解决方案是将字符串直接返回到响应中(当然还要设置内容类型):

<?php

header("Content-Type: application/json");

print $my_json_string;

?>
于 2013-06-24T10:25:39.777 回答