-3

How can I write a new file with my specific json's format? how can i do this with JSONObject? i need some java code and i want too save this file in assets. my json is:

{
    "word": "a",
    "Data": [
        {
            "meanings": [
                {
                    "meaning": "b",
                    "synonyms": [
                        "c"
                    ],
                    "examples": [
                        "d"
                    ]
                }
            ],
            "wordForms": ["e"],
            "word": "a",
            "pos": "g",
            "phoneticText": "h"
        }
    ]
}
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
joobin
  • 3
  • 4

2 Answers2

0

Have you tried to Google it ?

Look here: How to write a JSONObject to a file, which has JSONArray inside it, in Java?

Community
  • 1
  • 1
Russoul
  • 137
  • 1
  • 6
0

You can try this one. its simple. put your file in local for test. inside htdocs folder create a folder abc and inside it create a json file with .php extension and use the following code. works fine.

  <?php
   header('Content-type:application/json');
    mysql_connect('localhost','root','') or die(mysql_error());
   mysql_select_db('british');
     $select = mysql_query('SELECT id,title,content,photo from news ');

    $rows=array();
while($row=mysql_fetch_array($select))
{
  array_push($rows, array('id'=>$row[0],'title'=>$row[1],  
'content'=>strip_tags($row[2]), 
'photo'=>'http://10.0.2.2/json/images/'.$row[3]));
}
echo json_encode((array("result"=>$rows)));

 ?>