热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AngularJSxml数据到图表的json数据(已编辑)-AngularJSxmldatatojsondataforcharts(Edited)

Imhavingtroubleconvertingsomexmldatatojsondataintheformatitisexpected.Imnewtoal

I'm having trouble converting some xml data to json data in the format it is expected. I'm new to all of these techniques and the resources I find online are difficult for me to decypher. Using the app I make in my plnkr, I can take the data in the data.json file and use it to create the chart using a charts library. I have the xml in the data.xml file - I think that it is in the correct format in order to be converted to json in the required format. How do I use the x2js library in order to convert the xml to json and implement it into my chart? I've been stuck on this for a while now, and haven't been able to figure out how to get it working.

我无法以预期的格式将一些xml数据转换为json数据。我是所有这些技术的新手,我在网上找到的资源对我来说很困难。使用我在plnkr中创建的应用程序,我可以获取data.json文件中的数据并使用它来使用图表库创建图表。我在data.xml文件中有xml - 我认为它的格式正确,以便以所需的格式转换为json。如何使用x2js库将xml转换为json并将其实现到我的图表中?我现在已经坚持了一段时间,并且无法弄清楚如何让它发挥作用。

Currently, the app takes the data.json file and implements it into the data for the charts. What is the easiest way to take the xml and do the same?

目前,该应用程序获取data.json文件并将其实现为图表的数据。采取xml并执行相同操作的最简单方法是什么?

Edit: I've updated my plnkr with my attempt at converting the xml data to json. I even tried simply printing out the final data in json form - if the xml converted to json, but nothing came up. I entered a x2js.js file that has the functions from the library needed for the conversion I used in the service. I get the following error:

编辑:我已经尝试将xml数据转换为json,更新了我的plnkr。我甚至尝试简单地以json格式打印出最终数据 - 如果xml转换为json,但什么都没有出现。我输入了一个x2js.js文件,其中包含我在服务中使用的转换所需的库中的函数。我收到以下错误:

     ReferenceError: data is not defined
at new  (script.js:38)
at invoke (code.angularjs.org/1.2.2/angular.js:3641)
at Object.instantiate (code.angularjs.org/1.2.2/angular.js:3653)
at code.angularjs.org/1.2.2/angular.js:6684
at code.angularjs.org/1.2.2/angular.js:6097
at forEach (code.angularjs.org/1.2.2/angular.js:307)
at nodeLinkFn (code.angularjs.org/1.2.2/angular.js:6084)
at compositeLinkFn (code.angularjs.org/1.2.2/angular.js:5550)
at compositeLinkFn (code.angularjs.org/1.2.2/angular.js:5553)
at publicLinkFn (code.angularjs.org/1.2.2/angular.js:5458)

If anyone can help me out, its greatly appreciated.

如果有人可以帮助我,它非常感谢。

1 个解决方案

#1


1  

OK, You have a couple of problems here:

好的,你有几个问题:

The XML:

I took a small subset of your data and tried to see what the problem was:

我拿了一小部分数据,试图看看问题是什么:

Industry_countAuditFeesERNST & YOUNG LLP29812567000

x2js doesnt seem to like the & in your xml. Basically with the string ERNST & YOUNG you're breaking whatever it is x2js is trying to do internally.

x2js似乎不喜欢你的xml中的&。基本上使用字符串ERNST&YOUNG你会破坏x2js在内部尝试做的事情。

x2js.xml_str2json('Industry_countAuditFeesERNST & YOUNG LLP29812567000')

doesn't work whereas

不起作用

x2js.xml_str2json('Industry_countAuditFeesERNST YOUNG LLP29812567000')

works and gives a JS object as output. The only thing missing from the second one is the &.

工作并提供JS对象作为输出。第二个中唯一缺少的是&。

The Code:

I also removed the getData function and stopped passing the data variable into the service (You dont yet have data, which is why youre calling the service). Also added a success handler to set the scope variable.

我还删除了getData函数并停止将数据变量传递给服务(你还没有数据,这就是你调用服务的原因)。还添加了一个成功处理程序来设置范围变量。

Fully fixed working plnkr is here: http://plnkr.co/edit/uCLy42wnELYKq8S1DjYs?p=preview

完全固定的工作plnkr在这里:http://plnkr.co/edit/uCLy42wnELYKq8S1DjYs?p = preview


推荐阅读
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • SpringBoot uri统一权限管理的实现方法及步骤详解
    本文详细介绍了SpringBoot中实现uri统一权限管理的方法,包括表结构定义、自动统计URI并自动删除脏数据、程序启动加载等步骤。通过该方法可以提高系统的安全性,实现对系统任意接口的权限拦截验证。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 本文介绍了Java工具类库Hutool,该工具包封装了对文件、流、加密解密、转码、正则、线程、XML等JDK方法的封装,并提供了各种Util工具类。同时,还介绍了Hutool的组件,包括动态代理、布隆过滤、缓存、定时任务等功能。该工具包可以简化Java代码,提高开发效率。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • Java中包装类的设计原因以及操作方法
    本文主要介绍了Java中设计包装类的原因以及操作方法。在Java中,除了对象类型,还有八大基本类型,为了将基本类型转换成对象,Java引入了包装类。文章通过介绍包装类的定义和实现,解答了为什么需要包装类的问题,并提供了简单易用的操作方法。通过本文的学习,读者可以更好地理解和应用Java中的包装类。 ... [详细]
  • 如何查询zone下的表的信息
    本文介绍了如何通过TcaplusDB知识库查询zone下的表的信息。包括请求地址、GET请求参数说明、返回参数说明等内容。通过curl方法发起请求,并提供了请求示例。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 闭包一直是Java社区中争论不断的话题,很多语言都支持闭包这个语言特性,闭包定义了一个依赖于外部环境的自由变量的函数,这个函数能够访问外部环境的变量。本文以JavaScript的一个闭包为例,介绍了闭包的定义和特性。 ... [详细]
  • 本文介绍了Swing组件的用法,重点讲解了图标接口的定义和创建方法。图标接口用来将图标与各种组件相关联,可以是简单的绘画或使用磁盘上的GIF格式图像。文章详细介绍了图标接口的属性和绘制方法,并给出了一个菱形图标的实现示例。该示例可以配置图标的尺寸、颜色和填充状态。 ... [详细]
author-avatar
ayo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有