首页 \ 问答 \ Json数据转换为javascript数组(Json data into javascript array)

Json数据转换为javascript数组(Json data into javascript array)

var test=[];
$(document).ready(function(){
            $.getJSON("data.json",function(data){
                $.each(data,function(key,value){
                    test.push(value.topic);
                });
            });
        });

这是我的javacript代码。 我想用键作为主题推送json对象的所有值。 但是当我尝试访问test [i](我是数组长度内的任何整数)时,出现“undefined”错误。 我有什么困难?

这是我的json对象sample-

[
        {
            "topic": "Books",
            "quantity": 3
        },
        {
            "topic": "Grossery",
            "quantity": 3
        },
        {
            "topic": "stationery",
            "quantity": 3
        },
        {
            "topic": "food",
            "quantity": 2
        },
        {
            "topic": "market items",
            "quantity": 3
        }
]

var test=[];
$(document).ready(function(){
            $.getJSON("data.json",function(data){
                $.each(data,function(key,value){
                    test.push(value.topic);
                });
            });
        });

Here is my javacript code. I want to push json object's all values with key as topic. But when I try to access test[i] (i be any integer within array length) I get an error "undefined" . What' am I msissing?

Here is my json object sample-

[
        {
            "topic": "Books",
            "quantity": 3
        },
        {
            "topic": "Grossery",
            "quantity": 3
        },
        {
            "topic": "stationery",
            "quantity": 3
        },
        {
            "topic": "food",
            "quantity": 2
        },
        {
            "topic": "market items",
            "quantity": 3
        }
]

原文:https://stackoverflow.com/questions/50134338
更新时间:2023-02-22 12:02

最满意答案

在DB(而不是Text )中将description字段定义为Memo ,然后从ADOQuery1删除所有持久字段,然后再次添加它们,以便ADOQuery1codemeaning_description类型为ftMemo

无需逃跑或取代CRLF


Define your description field as Memo in the DB (instead of Text), and then remove all your persistent fields from ADOQuery1, and add them again so that ADOQuery1codemeaning_description type is ftMemo.

No need to escape or replace CRLF.

相关问答

更多
  • 有可能使用内置到Access中的Jet复制,但我会警告你,它非常脆弱。 它也会在你做任何表的时候搞乱你的PK,因为它会选择随机签名整数来避免重要冲突,所以你最终可能会以-1243482392912作为你在给定记录上的下一个PK。 如果你正在做任何类型的查询(如客户ID,订单号等),那么这是一个PITA。你不能自动化Access同步(也许你可以通过使用VBA来伪造类似的东西,但仍然,只有在打开数据库时才会运行)。 我建议的方法是在您的“中央”数据库上使用SQL Server 2005/2008,并在您的“远程 ...
  • 我最近遇到了类似的问题,我解决这个问题的方法是在PowerPivot(64位)中构建主数据库 - 这是一个免费的Excel加载项,可轻松连接到Access和Excel。 随着在其他数据库中添加或更改更多数据,PowerPivot(64位)引擎非常快速将自动处理数据刷新。 希望这可以帮助。 I had a similar problem recently and the way I solved this was to build the master database in PowerPivot(64bit ...
  • 在DB(而不是Text )中将description字段定义为Memo ,然后从ADOQuery1删除所有持久字段,然后再次添加它们,以便ADOQuery1codemeaning_description类型为ftMemo 。 无需逃跑或取代CRLF 。 Define your description field as Memo in the DB (instead of Text), and then remove all your persistent fields from ADOQuery1, and ...
  • 您可以使用线条集合的开始/结束更新: memo.Lines.BeginUpdate; try memo.Lines.Add('test'); finally memo.Lines.EndUpdate; end; You can use begin/end update for lines collection: memo.Lines.BeginUpdate; try memo.Lines.Add('test'); finally memo.Lines.EndUpdate; end;
  • 这常常被误引和误解。 这里的建议也是正确的。 因此,所谓的JET数据库引擎已经成为Windows的一部分,并作为默认安装组件预先安装了10多年。 实际上它是Windows 98SE的默认值。 这意味着一个全新的开箱即用的Windows机器可能没有安装软件使用像Windows脚本这样的东西可以打开这些Access文件。 所以你可以从VB.net,c#等打开这些文件,而无需任何额外安装的组件。 但请记住,自2007年以来,如果使用新的accDB格式文件而不是mdb,则必须安装较新版本的JET引擎。 此较新版本的 ...
  • 只需从我的网站添加一些页面到这个讨论。 您想要将MDB拆分为包含查询,表单,报表,宏和模块的前端MDB,只需在后端MDB中包含表和关系。 FE被复制到每个网络用户计算机。 FE MDB链接到驻留在服务器上的后端MDB中的表。 您可以更新FE MDB并将其分发给用户,可能是MDE。 有关更多信息,请参阅“将应用程序分成前端和后端提示”页面。 请参阅免费的Auto FE更新程序实用程序,以使新FE的分发相对简单。该实用程序还非常好地支持终端服务器/ Citrix。 另请访问我的Access Performanc ...
  • 不要使用null布局和setBounds(...)。 Swing旨在与布局管理器一起使用。 不需要comboBox.setVisible(true)因为默认情况下Swing组件(顶级容器除外)是可见的。 为什么它总是抱怨并建议抑制警告? 您尚未指定将添加到组合框模型的数据类型。 您正在添加字符串数据,因此您应该使用: JComboBox combo = new JComboBox(); 阅读泛型 ,了解更多信息。 如何从数据库中允许多个项目在jcombobox中? 你没有做 ...
  • 您必须将ScrollBars属性设置为ssHorizontal,ssVertical或ssBoth ,并将IMouse单元添加到您的项目中。 UPDATE 为避免IMouse单元导致的内存泄漏,必须在应用程序退出之前添加此代码(例如,在主单元的finalization部分中)。 if Assigned(Mouse.PanningWindow) then Mouse.PanningWindow := nil; You must set the ScrollBars property to ssH ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)