drq22639
drq22639
2011-12-23 12:43

我可以从JSON动态创建mySQL表吗?

  • create-table
  • json
  • php
  • dynamic
  • mysql

Let's say I have a server side script which generates JSON from a simple select on a table. The JSON is encoded in the 1st script.

I have no control over this 1st script, but am aware when the underlying database structure changes and when the JSON structure changes.

Script 2 uses CURL to get the .js file (contents) which contains the JSON, I can then decode into an array.

What I need to do then is store the data in another database.

My question is basically about automating this process and being able to create a table from an array when you don't know what the structure of the array is until it arrives.

Can it be done?

EDIT Added the JSON as it currently stands, but the point is it might change.

{"name": "Google",
 "homepage_url": "http://www.google.com",
 "blog_url": "",
 "blog_feed_url": "",
 "twitter_username": "",
 "category_code": "ecommerce",
 "tag_list": "retail-portal-online-shopping-markets",
 "alias_list": null,
 "image": null,
 "products":
  [],
 "relationships":
  [],
 "competitions":
  [],
 "providerships":
  [{"title": "Legal",
    "is_past": false,
    "provider":
     {"name": "TaylorWessing",
      "permalink": "taylorwessing"}}],
 "offices":
  [{"description": "European HQ",
    "address1": "",
    "address2": "",
    "zip_code": "",
    "city": "Brussels",
    "state_code": null,
    "country_code": "BEL",
    "latitude": null,
    "longitude": null}]}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答

为你推荐

换一换