我可以从JSON动态创建一个mySQL表吗? [英] Can I dynamically create a mySQL table from JSON?

查看:157
本文介绍了我可以从JSON动态创建一个mySQL表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个服务器端脚本,可以从表上的简单选择生成JSON。 JSON在第一个脚本中编码。



我无法控制第一个脚本,但是我们知道底层数据库结构发生变化以及JSON结构何时改变。 / p>

脚本2使用CURL获取包含JSON的 .js 文件(内容),然后我可以解码为一个数组。



然后我需要做的是将数据存储在另一个数据库中。



我的问题是基本上关于自动化这个过程,并且当您不知道数组的结构到达之前,可以从数组创建一个表。



可以是完成?



编辑添加了目前所使用的JSON,但重要的是它可能会改变。

  {name:Google,
homepage_url:http://www.google.com,
blog_url $
twitter_username:,
category_code:电子商务,
tag_list:门户网站,在线订购
bbbb
bb
b
[],
竞赛:
[],
providerships:
[{title:Legal,
is_past :false,
provider:
{name:TaylorWessing,
permalink:taylorwessing}}],
office:
[{description:European HQ,
address1:,
address2:,
zip_code:,
城市:布鲁塞尔,
state_code:null,
country_code:BEL,
纬度:null,
longitude:null} ]}


解决方案

我会在问题旁边回答,但如果你想存储JSON为什么不使用文档数据库? CouchDB 沙发存储您的JSON原样,无需进行任何处理。


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}]}

解决方案

I will answer next to the question but if you want to store JSON why not use a document database? CouchDB couch store your JSON "as is" without you having to do any processing.

这篇关于我可以从JSON动态创建一个mySQL表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆