我正在尝试向 api 发送请求,但我得到的响应很奇怪。
我将回复作为图片附上。
这是文本中的真实 XML 响应
<data type="array" class_name="Location" skip="0" limit="0">
<Location>
<_id>558a8325535c1246bb00d5c5</_id>
<_parent_id>test-api</_parent_id>
<created-at type="integer">1435140901</created-at>
<lat type="float">11.0270643</lat>
<location>Avarampalayam, Coimbatore, Tamil Nadu, India</location>
<long type="float">76.9830277</long>
<updated-at type="integer">1435140901</updated-at>
<user-id type="integer">3566216</user-id>
</Location>
<Location>
<_id>558a83dd535c12843900dbbe</_id>
<_parent_id>test-api</_parent_id>
<created-at type="integer">1435141085</created-at>
<lat type="float">11.0310806</lat>
<location>Mettupalayam Bus Stand, Mettupalayam Road, Tatabad, Coimbatore, Tamil Nadu, India</location>
<long type="float">76.9525282</long>
<updated-at type="integer">1435141085</updated-at>
<user-id type="integer">3566216</user-id>
</Location>
</data>
在 #document 下
我如何获取上述给定响应中的值?
这是我用来请求的方式
$.ajax({
url: 'https://api.quickblox.com/data/Location',
data: { token:'662d3330f192b4af77d5eef8de58f7e8c01a12a7' },
method: 'get',
success: function(msg) {
var value = msg;
console.log(msg);
}
})
最佳答案
您可以对返回的 XML 使用 jQuery 的标准 DOM 遍历函数来检索您需要的值。试试这个:
$.ajax({
url: 'https://api.quickblox.com/data/Location',
data: {
token:'662d3330f192b4af77d5eef8de58f7e8c01a12a7'
},
method: 'get',
dataType: 'xml', // note this is optional as jQuery should detect and parse it for you automatically
success: function(xml) {
$(xml).filter('data').find('Location').each(function() {
var id = $(this).find('_id').text();
var parentId = $(this).find('_parent_id').text();
var createdAt = new Date($(this).find('created-at').text());
var lat = parseFloat($(this).find('lat').text());
// retrieve the other properties...
// work with them here...
});
}
});
关于php - 解析 xml 响应奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31024364/
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
我正在使用ruby2.1.0我有一个json文件。例如:test.json{"item":[{"apple":1},{"banana":2}]}用YAML.load加载这个文件安全吗?YAML.load(File.read('test.json'))我正在尝试加载一个json或yaml格式的文件。 最佳答案 YAML可以加载JSONYAML.load('{"something":"test","other":4}')=>{"something"=>"test","other"=>4}JSON将无法加载YAML。JSON.load("
在我做的一些网络开发中,我有多个操作开始,比如对外部API的GET请求,我希望它们同时开始,因为一个不依赖另一个的结果。我希望事情能够在后台运行。我找到了concurrent-rubylibrary这似乎运作良好。通过将其混合到您创建的类中,该类的方法具有在后台线程上运行的异步版本。这导致我编写如下代码,其中FirstAsyncWorker和SecondAsyncWorker是我编写的类,我在其中混合了Concurrent::Async模块,并编写了一个名为“work”的方法来发送HTTP请求:defindexop1_result=FirstAsyncWorker.new.async.
我想用Nokogiri解析HTML页面。页面的一部分有一个表,它没有使用任何特定的ID。是否可以提取如下内容:Today,3,455,34Today,1,1300,3664Today,10,100000,3444,Yesterday,3454,5656,3Yesterday,3545,1000,10Yesterday,3411,36223,15来自这个HTML:TodayYesterdayQntySizeLengthLengthSizeQnty345534345456563113003664354510001010100000344434113622315
我使用的第一个解析器生成器是Parse::RecDescent,它的指南/教程很棒,但它最有用的功能是它的调试工具,特别是tracing功能(通过将$RD_TRACE设置为1来激活)。我正在寻找可以帮助您调试其规则的解析器生成器。问题是,它必须用python或ruby编写,并且具有详细模式/跟踪模式或非常有用的调试技术。有人知道这样的解析器生成器吗?编辑:当我说调试时,我并不是指调试python或ruby。我指的是调试解析器生成器,查看它在每一步都在做什么,查看它正在读取的每个字符,它试图匹配的规则。希望你明白这一点。赏金编辑:要赢得赏金,请展示一个解析器生成器框架,并说明它的