获取对象属性的值,其中键是空字符串 [英] Getting the value of an object's property where the key is a blank string

查看:81
本文介绍了获取对象属性的值,其中键是空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于此对象:

: http://www.w3.org/2005/Atom
gd: http://schemas.google.com/g/2005 
openSearch: http://a9.com/-/spec/opensearch/1.1/ 
app: http://www.w3.org/2007/app; 
media: http://search.yahoo.com/mrss/

我如何获取第一个属性的值?我怀疑这是一个简单的过程,但我画了一个空白。在此先感谢。

How do I get the value of the first property? I suspect this is an easy process, but I'm drawing a blank. Thanks in advance.

对象构建如下:

服务器端(php):

$namespaces = $feedXML->getNamespaces(true);
$arr = array(
'Status' => 'Success',
'Message' => 'Feed fetched.',
'Namespaces' => $namespaces,
'Feed XML' => $feedXML
);
echo json_encode($arr);

客户端(JS):

   var output = '';
    for (property in dataj["Namespaces"]) {
        output += property + ': ' + dataj["Namespaces"][property] + '; ';
    }
    alert(output);

我希望能够检查命名空间,看看它是Atom还是RDF。

I would like to be able to check the namespaces to see if this is Atom or RDF.

听起来只是迭代每个属性将是最好的方式。

It sounds like just iterating each property is going to be the best way.

推荐答案

如果您尝试获取其键为空字符串的属性的值,则可以执行

If you're trying to get the value of the property whose key is an empty string, then you can do

var value = myObject[''];

如果你试图得到一个对象的第一个属性,你不能因为属性在javascript对象没有订购。

If you try to get the "first property" of an object, you can't because properties in javascript objects aren't ordered.

这篇关于获取对象属性的值,其中键是空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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