首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSL尝试让JSON正常工作

XSL尝试让JSON正常工作
EN

Stack Overflow用户
提问于 2014-06-06 00:18:29
回答 2查看 114关注 0票数 1

正在尝试获取XML..

代码语言:javascript
复制
<user-types>
    <section id="11" handle="user-types">User types</section>
    <entry id="9">
        <name mode="unformatted" handle="home-owner" word-count="2" lang="en" handle-en="home-owner"><![CDATA[Home owner]]></name>
    </entry>
    <entry id="7">
        <name mode="unformatted" handle="contractor-residential" word-count="2" lang="en" handle-en="contractor-residential"><![CDATA[Contractor (residential)]]></name>
    </entry>
    <entry id="8">
        <name mode="unformatted" handle="contractor-non-residential" word-count="2" lang="en" handle-en="contractor-non-residential"><![CDATA[Contractor (non-residential)]]></name>
    </entry>
    <entry id="10">
        <name mode="unformatted" handle="commercial-property-owner" word-count="3" lang="en" handle-en="commercial-property-owner"><![CDATA[Commercial property owner]]></name>
    </entry>
</user-types>

要成为JSON,但标记entry没有转换为数组,所以JS只能读取其中之一:(

当前损坏的JSON输出

代码语言:javascript
复制
{
"user-types" : {
    "section" : {
        "@attributes" : {
            "id" : 11,
            "handle" : "user-types"
        },
        "value" : "User types"
    },
    "entry" : {
        "@attributes" : {
            "id" : 9
        },
        "name" : {
            "@attributes" : {
                "mode" : "unformatted",
                "handle" : "home-owner",
                "word-count" : 2,
                "lang" : "en",
                "handle-en" : "home-owner"
            },
            "value" : "Home owner"
        }
    },
    "entry" : {
        "@attributes" : {
            "id" : 7
        },
        "name" : {
            "@attributes" : {
                "mode" : "unformatted",
                "handle" : "contractor-residential",
                "word-count" : 2,
                "lang" : "en",
                "handle-en" : "contractor-residential"
            },
            "value" : "Contractor (residential)"
        }
    },
    "entry" : {
        "@attributes" : {
            "id" : 8
        },
        "name" : {
            "@attributes" : {
                "mode" : "unformatted",
                "handle" : "contractor-non-residential",
                "word-count" : 2,
                "lang" : "en",
                "handle-en" : "contractor-non-residential"
            },
            "value" : "Contractor (non-residential)"
        }
    },
    "entry" : {
        "@attributes" : {
            "id" : 10
        },
        "name" : {
            "@attributes" : {
                "mode" : "unformatted",
                "handle" : "commercial-property-owner",
                "word-count" : 3,
                "lang" : "en",
                "handle-en" : "commercial-property-owner"
            },
            "value" : "Commercial property owner"
        }
    }
}
}

使用这个XSL https://github.com/iwyg/xml-to-json

EN

回答 2

Stack Overflow用户

发布于 2014-06-12 03:00:25

票数 0
EN

Stack Overflow用户

发布于 2014-06-06 06:04:47

根据xml- to -json的文档,这似乎不打算以这种方式使用。

使用此文档会生成一个数组:

代码语言:javascript
复制
<user-types>
    <section id="11" handle="user-types">User types</section>
    <entry>
        <item id="9">
            <name mode="unformatted" handle="home-owner" word-count="2" lang="en"
                  handle-en="home-owner"><![CDATA[Home owner]]></name>
        </item>
        <item id="7">
            <name mode="unformatted" handle="contractor-residential" word-count="2" lang="en"
                  handle-en="contractor-residential"><![CDATA[Contractor (residential)]]></name>
        </item>
        <item id="8">
            <name mode="unformatted" handle="contractor-non-residential" word-count="2" lang="en"
                  handle-en="contractor-non-residential"><![CDATA[Contractor (non-residential)]]></name>
        </item>
        <item id="10">
            <name mode="unformatted" handle="commercial-property-owner" word-count="3" lang="en"
                  handle-en="commercial-property-owner"><![CDATA[Commercial property owner]]></name>
        </item>
    </entry>
</user-types>

结果看起来像你想要的那样吗?你能用这种方式修改你的XML吗?否则,恐怕您将不得不对xml- to -json进行更改,以便能够处理您的xml结构。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24065275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档