forumnz Posted May 8, 2009 Share Posted May 8, 2009 I have a script that outputs data like this: {success: true, data: [{"id":"1","fld1":"text","fld2":"text","fld3":"text","fld4":"text","fld5":"text","fld6":"text","fld7":"text","fld8":"text"}, {"id":"2","fld1":"text","fld2":"text","fld3":"text","fld4":"text","fld5":"text","fld6":"text","fld7":"text","fld8":"text"}], form: {"fld9":"text","fld10":"text","fld11":"text","fld12":"text"}} How can turn that first part of it (the lines that start with id) into an array? Thanks a lot Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/ Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 You want to turn that into an array in PHP or JavaScript? Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829059 Share on other sites More sharing options...
forumnz Posted May 8, 2009 Author Share Posted May 8, 2009 In PHP Is that possible? Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829062 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Check out json_decode Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829065 Share on other sites More sharing options...
forumnz Posted May 8, 2009 Author Share Posted May 8, 2009 Thanks Ken2k7! I'll do that now Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829068 Share on other sites More sharing options...
forumnz Posted May 8, 2009 Author Share Posted May 8, 2009 Ok that all makes sense so far - I just have one question: The script outputs as above, but how do I take the POSTed code and place it into a variable? Thanks Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829073 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 $arr = json_decode($str); Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829081 Share on other sites More sharing options...
forumnz Posted May 8, 2009 Author Share Posted May 8, 2009 Thanks but what I meant was that the JS posts the data, and the output is as above. I think I may have to refer to the JS, but what would I need to write in the PHP form, to 'retrieve' the POSTed data and put it into a variable? Link to comment https://forums.phpfreaks.com/topic/157298-solved-output-code/#findComment-829089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.