Hi, this is my first time trying to create some code in PHP and it took me a long time but I am capable. Now to convert data into XML, I need to create a JSON object and it is not running properly. The biggest problem is trying to create a new class in PHP (I do not know what I have done right or not) and if this is the right way to enclose this list, I think that something good is from this but for me Since I only use Java and C # it seems a bit crazy. I think I'm doing something wrong showing me an error which is the line
$ array ['data'] - & gt; Attached (new cake ($ name, $ content, $ ready, $ image)); But I do not know what I'm doing wrong I have not yet written the line in which the array is included in JSN and changed thanks
< Code> // opens, if it does not exist, then it creates $ indicator = FOPN ($ file, "W"); // json $ cake_list ['data'] is written in = new SplObjectStorage (); {// SQL data takes $ name = mysql_result ($ sql, $ i, "B.nome") for ($ I = 0; $ i & lt; $ row; $ i ++); $ Content = mysql_result ($ sql, $ i, "begirdities"); $ Ready = mysql_result ($ sql, $ i, "beeppero"); $ Image = mysql_result ($ sql, $ i, "B.imagem"); // contains the XML tag // $ content = "{"; $ // content = "}"; $ Array ['data'] - & gt; Attach (new cake ($ name, $ content, $ ready, $ image)); $ // content = ","; // file resonated // file resonance; $ Content = json_encode ($ content); FILIT ($ indicator, $ content); // resonance $ content; } // echo the cake_list for off; // close the file fclose ($ pointer); // message // echo "file & lt; b & gt;" $ File. "& Lt; / b & gt; was successfully created!"; // If it stops ($ line) square cake {var $ name; Var $ content; Var $ Ready; Var $ image; Public function __ composition ($ name, $ content, $ ready, $ image) {$ this- & gt; Name = $ name; $ This- & gt; Content = $ content; $ This- & gt; Ready = $ ready; $ This- & gt; Image = $ image; }} Create_instance function ($ square, $ arg1, $ arg2, $ arg3, $ arg4) {$ reflection_class = new reflection class ($ square); Refund $ reflection_class-> New intersection ($ arg1, $ arg2, $ arg3, $ arg4); }
The error you are receiving is because you $ array ['Data'] When you mean $ cake_list ['data'] change the error line to: $ cake_list ['data' ] - & gt; Attached (new cake ($ name, $ content, $ ready, $ picture)); The easiest way to do JSON objects (or more accurately to represent the string of a JSON object) is to:
$ array = Array ('name' = & gt; $ name, 'content' = & gt; $ element, 'ready' = & gt; $ ready; 'image' = & gt; $ image); $ Json = json_encode ($ array); You can also make things easy to use in this way:
$ myObject = new stdClass (); // stdClass () PHP $ myObject- & gt; Name = $ is the common square in the name; $ MyObject- & gt; Content = $ content; $ MyObject- & gt; Ready = $ ready; $ MyObject- & gt; Image = $ image;
No comments:
Post a Comment