简体   繁体   English

带有http,标头,元数据和正文的JSON响应

[英]JSON response with http, header, meta and body

I'm developing an iPhone application with latest SDK and XCode 4.2. 我正在使用最新的SDK和XCode 4.2开发iPhone应用程序。

I'm trying to parse a JSON response. 我正在尝试解析JSON响应。 It is the first time I do it and I'm not sure which is the correct format from a JSON response. 这是我第一次这样做,不确定从JSON响应中选择哪种格式。

From a web service I'm getting this: 从网络服务我得到这个:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
{"rules": [
{ "id_categoria": "3","categoria": "cat03" },{ "id_categoria": "2","categoria": "cat02" }
     ]
   }</body>
</html>

Is it correct to find html, head, meta, and body tags in a JSON response? 在JSON响应中找到html,head,meta和body标签是否正确?

By the way, I'm using this JSON parser: https://github.com/stig/json-framework/ 顺便说一下,我正在使用此JSON解析器: https : //github.com/stig/json-framework/

And I think JSON response it also incorrect. 而且我认为JSON响应也不正确。 Its XML equivalent is: 其XML等效项是:

<?xml version="1.0" encoding="UTF-8"?>
<rules>
    <id_categoria>3</id_categoria>
    <categoria>cat03</categoria>
</rukes>
<rules>
    <id_categoria>2</id_categoria>
    <categoria>cat02</categoria>
</rules>

Is this XML correct? 这个XML正确吗?

I think a correct JSON response could be: 我认为正确的JSON响应可能是:

{
    "data": {
        "rules": [
            {
                "id_categoria": "3","categoria": "cat03"
            },
            {
                "id_categoria": "2","categoria": "cat02"
            }
        ]
    }
}

Which its XML equivalent is: 其XML等效项是:

<?xml version="1.0" encoding="UTF-8"?>
<data>
    <?xml version="1.0" encoding="UTF-8"?>
    <rules>
        <id_categoria>3</id_categoria>
        <categoria>cat03</categoria>
    </rukes>
    <rules>
        <id_categoria>2</id_categoria>
        <categoria>cat02</categoria>
    </rules>
</data>

I'm lost. 我迷路了。 Which is the correct format for JSON Response? JSON响应的正确格式是什么?

No, that's invalid JSON. 不,那是无效的JSON。 The web service really needs to fix it - it'd be possible to parse the JSON out with some work, but it definitely shouldn't be designed to work this way. Web服务确实需要对其进行修复-可以通过一些工作来解析JSON,但是绝对不应该将其设计为以这种方式工作。

The valid JSON is between the <body> tags: 有效的JSON在<body>标记之间:

{
    "rules": [
        {
            "id_categoria": "3",
            "categoria": "cat03"
        },
        {
            "id_categoria": "2",
            "categoria": "cat02"
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM