php - Getting correct JSON format -
So I'm trying to create a JSON object about which I should have some information about some questions Is a pseudo code that I want to present:
{"page": 1, "info": {"id": 1, "type": 3, "description": " {"Id": 1, "description": "dunno"} {"id": 2, "description" id ": 3," description ":" I want to show you I'm refusing "}}" id ": 2," Type ": 1," Description ":" Do you want it? The brief? "," Option ": {" id ": 1," description ":" yes "} {" id ": 2," description ":" no "}}} The code below Nightmare (one of the answers), and what I want to do with this page and questions, but I do not know how to connect the options of each question. You can see a snippet given, where I have tried, but it is not spelled correctly and I'm stopping it for a while. $ befo Re_json_encode [$ row ['page']] [] '] =' ('id' => $ line ['id'], 'type' = & gt; $ line ['type'], 'description' = & Gt; $ line ['description'], 'option' = & gt; $ alternativesarray // im not sure about, do not know the framework of the optional array;) < P> Another Illustration I want a hierarchy to reveal JSON data. I should be able to choose for example: All the options for all the questions on a specific page. Page 3 Shn want to generate so I can get the first 3 pages question within the sub-array, and then gain access to each question to all associated options sub-array yourself that question. Sorry for the bad explanation of my problem, it's just a bit complicated: Page questions Optional Optional Optional Optional Optional Optional Optional Optional Optional Optional Optional Optional Optional Option > Update: 3 layer: $ rows_test2 [$ r ['page']] ['id' = & gt; $ R ['id'], 'type' = & gt; $ R ['type'], 'description' = & gt; $ R ['Description']] [] = Array ('altid' => $ t ['altid'], 'altdesc' => $ t ['altdesc']); $ rows [=] array ("page" = & gt; 1, "info" = & gt; array ("id" => 1, "type" => 3, "description" = & gt; 'desc',)); Echo json_encode ($ rows); // [{"page": 1, "info": {"id": 1, "type": 3, "description": "desc"}}] Update: $ alternativesarray [] = array ('id' => 1 ',' description '=>' yes'); $ Option [] = array ('id' = & gt; '2', 'description' = & gt; 'no'); $ Line [] = array ("page" => 1, "info" => array ("id" => 2, "type" = & gt; 3, "description" = & gt; 'Desc', 'option' => $ alternativesarray); print json_encode ($ rows); "" "" "," option ":" {{"}", "option": ["id": 1 , "Info": {"id": 2, "type": 3, "description" description ":" yes "}, {" id ":" 2 "," description ":" no "}]}}}
Comments
Post a Comment