json解析(一)

客户端和服务器端的交互统一采用http get方式,如果有接口要采用 http post方式可以提出来。下面是以获取首页信息为例简单的阐述一下协议,
http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do为统一请求的URL地址,m=xxxx为你请求的服务,如果需要传递参数在后面添加,例如:
http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=get_magazine_detail&issue=316
获取杂志目录信息为例组装的url,m=get_magazine_detail表示请求获取杂志信息服务,issue=316表示要获取的第几期杂志的信息。



获取首页:
    CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=get_total_issue HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 \r\n
		Connection: Keep-Alive\r\n

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":   
        {
            "data":
            [
                {
                		"issue_title":"美女杂志1",
                		
                		"img":
	                	{
	                				"name":"218_issue.png",
	                				"url":"http://10.0.2.2:8080/HttpsServer/one.jpg"
	                	},
                    "issue_number":"2012第3期",
                    "issue_id":"218",
                    "type":"h3c",
                    "pubdate":"2012年3月14日"
                },
                {
                		"issue_title":"美女杂志2",           		
                		"img":                		
	                	{
	                				"name":"218_issue.png",
	                				"url":"http://10.0.2.2:8080/HttpsServer/two.jpg"
	                	},
                    "issue_number":"2012第3期",
                    "issue_id":"218",
                    "type":"h3c",
                    "pubdate":"2012年3月14日"
                },
                {
                		"issue_title":"美女杂志3",           		
                		"img":                		
	                	{
	                				"name":"218_issue.png",
	                				"url":"http://10.0.2.2:8080/HttpsServer/three.jpg"
	                	},
                    "issue_number":"2012第3期",
                    "issue_id":"218",
                    "type":"h3c",
                    "pubdate":"2012年3月14日"
                },
                {
                		"issue_title":"美女杂志4",           		
                		"img":                		
	                	{
	                				"name":"218_issue.png",
	                				"url":"http://10.0.2.2:8080/HttpsServer/four.jpg"
	                	},
                    "issue_number":"2012第3期",
                    "issue_id":"218",
                    "type":"h3c",
                    "pubdate":"2012年3月14日"
                },                
                {
                		"issue_title":"美女杂志5",
                		"img":
	                		{
	                				"name":"218_issue.png",
	                				"url":"http://10.0.2.2:8080/HttpsServer/five.jpg"
	                		},
                    "issue_number":"2012第3期",
                    "issue_id":"218",
                    "type":"h3c",
                    "pubdate":"2012年3月14日"
                }
            ]
        }
    }


获取往期杂志页:
    CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=get_magazine_old_datail HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 \r\n
		Connection: Keep-Alive\r\n

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {
            "data":
            [
                {
                  "issue_year":"2011年度财经杂志",
                    "type":"h3c",

		    						"magazine_old_list":
									   [
												{
														"issue_id":"218",
														"issue_number":"2012第3期",
                    				"issue_title":"铁路投融变道",
														"pubdate":"2012年3月14日"
												},
												{
														"issue_id":"218",
														"issue_number":"2012第3期",
														"issue_title":"铁路投融变道",
														"pubdate":"2012年3月14日"
												}
									   ]
                }
            ]
        }
    }

获取杂志目录页面:
    CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=get_magazine_datail&issue_id=218 HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 \r\n
		Connection: Keep-Alive\r\n

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {
						"issue_title":"致命的集资",
						"issue_number":"2012第3期",
						"issue_id":"218",
						"type":"h3c",
						"pubdate":"2012年3月14日",
						
						"img":
						[
								{
										"img_name":"218_issue.png",
										"img_url":"http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/218_issue.png",
								},
						]
						
						"magazine_list":
						[
							{
									"article_type":"封面文章CoverStory"
				
									"magazine_data":
									[
											{
													"article_id":"322"
													"article_name":"回归可持续性",
													"article_author":"迈克尔*斯宾赛/文"
											},
											{
													"article_id":"322"
													"article_name":"回归可持续性",
													"article_author":"迈克尔*斯宾赛/文"
											}
									]
							},
							{
									"article_type":"<财经>动态CaijingTopics"
				
									"magazine_data":
									[
											{
													"article_id":"322"
													"article_name":"回归可持续性",
													"article_author":"迈克尔*斯宾赛/文"
											},
											{
													"article_id":"322"
													"article_name":"回归可持续性",
													"article_author":"迈克尔*斯宾赛/文"
											}
									]
							}
						]
        }
    }
    
获取调查页:
    CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=get_survey HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 \r\n
		Connection: Keep-Alive\r\n

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {
		        data:
		        [
				        {
					         	"survey_title":"你怎么看雷锋精神?",
					         	"survey_date":"2012年03月05日14:18",
					         	"survey_people_number":"当前共有701人参加"
					         	"survey_content":"调查问题的内容"
					          "type":"h3c",  
					           
										"survey_result":
									   [
												{
														"result_id":"123" ,
														"result_name":"赞同",
														"result_number":"282支持"
												},
												{
														"result_id":"123" ,
														"result_name":"不赞同",
														"result_number":"395支持"
												},
												{
														"result_id":"123" ,
														"result_name":"说不清",
														"result_number":"75支持"
												}
									   ]
				        },
				        {
					         	"survey_title":"你怎么看雷锋精神?",
					         	"survey_date":"2012年03月05日14:18",
					         	"survey_people_number":"当前共有701人参加"
					         	"survey_content":"调查问题的内容"
					          "type":"h3c",  
					           
										"survey_result":
									   [
												{
														"result_id":"123" ,
														"result_name":"赞同",
														"result_number":"282支持"
												},
												{
														"result_id":"123" ,
														"result_name":"不赞同",
														"result_number":"395支持"
												},
												{
														"result_id":"123" ,
														"result_name":"说不清",
														"result_number":"75支持"
												}
									   ]
				        }
		        ]
		    }
    }

判断是否有新杂志:
    CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=is_new_magazine HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 \r\n
		Connection: Keep-Alive\r\n

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {
						"isUpdates":"0" // 0:表示没有新杂志,1:表示有新杂志更新
        }
    }
    
获取文章主体内容:
 CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=request_article_data&issure_id=320&article_id=20 HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91)     AppleWebKit/533.1 \r\n
    Connection: Keep-Alive\r\n
    

    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {         
	          "brief":"摘要内容",
	          "content":"文章内容",
            "imageurl":
            [              
                  {
                   "name":"致命的集资1.png",                                                                    
                   "url":"http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/218_issue1.png"                        
                  },
                  {
                   "name":"致命的集资2.png",                                                                    
                   "url":"http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/218_issue2.png"
                   }
            ]
        }
    }


上传文章评分内容:
 CLIENT -> SERVER
    ----------------------------------------------------------------
    GET  GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=upload_article_grade&issure_id=320&article_id=20&grade=4 HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91)     AppleWebKit/533.1 \r\n
    Connection: Keep-Alive\r\n
    
    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {         
	          "response":"Thanks",
            
        }
    }



获取文章评论内容:
 CLIENT -> SERVER
    ----------------------------------------------------------------
    GET http://xxx.xxx.xxx.xxx:xxxx/mobile_mag/api.do?m=request_article_criticism&issure_id=320&article_id=20 HTTP/1.0\r\n
    Host: xxx.xxx.xxx.xxx\r\n
    User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91)     AppleWebKit/533.1 \r\n
    Connection: Keep-Alive\r\n
    
    SERVER -> CLIENT
    ----------------------------------------------------------------
    HTTP/1.0 200 OK\r\n
    Server: VanceInfoMobile_mag/1.0.00\r\n
    Connection: Keep-Alive\r\n
    Content-Type: application/json\r\n
    \r\n
    {
        "protocol":"Mobile_mag/1.0",
        "status":"200", 
        "results":
        {         
            "data":
            [       
		           {
                   "nickname":"李四",                                                       
                   "create_time":"2012-03-15 13:00:00",                    
		               "content":"很好,很强大"
                },  
                {
                   "nickname":"张三",                                                        
                   "create_time":"2012-03-15 12:00:00",                    
		               "content":"这是什么破文章啊"
                }                
            ]
        }
    }

你可能感兴趣的:(json解析)