当前位置: 代码迷 >> Ajax >> ajax json,该怎么解决
  详细解决方案

ajax json,该怎么解决

热度:293   发布时间:2012-05-10 16:02:39.0
ajax json
加载另一个程序jsonGene.jsp生成json数据的代码是:
JScript code

            function show(){
                $.getJSON(
                    "jsonGene.jsp", 
                    function(data){
                        $.each(data, function(index, values){
                            $.each(values, function(key, value){
                                $("#page").append(value + "<br>");
                            });
                        });
                    });
                sHeight = 0;
                sTop = 0;
                }


总是读不出来,但是我把程序生成的json数据存在文件中,url改成文件名就能读出来。
生成的Json数据是:
[
  {
  "patternTypes": "PER,CIT",
  "pattern1": "1177_3_14_;",
  "label": "negPlace",
  "value": "0.5",
  "anotherPattern1": "knock.v DATE @"
  },
  {
  "patternTypes": "PER,CIT",
  "pattern1": "126_14_53_;14_53_24_;",
  "label": "isInCity",
  "value": "0.38888889",
  "anotherPattern1": "marry.v in.p"
  },
  {
  "patternTypes": "PER,CIT",
  "pattern1": "14_53_24_;",
  "label": "isInCity",
  "value": "0.5",
  "anotherPattern1": "marry.v in.p"
  },
  {
  "patternTypes": "PER,CIT",
  "pattern1": "14_628_24_;",
  "label": "isInCity",
  "value": "1.0",
  "anotherPattern1": "arrive.v in.p"
  },
  {
  "patternTypes": "PER,CIT",
  "pattern1": "1505_75_42_;75_42_14_;",
  "label": "negPlace",
  "value": "0.3640873",
  "anotherPattern1": "score.v goal.n against.p @"
  },
  {
  "patternTypes": "PER,CIT",
  "pattern1": "1505_75_42_;75_42_14_;",
  "label": "negPlace",
  "value": "0.3640873",
  "anotherPattern1": "score.v goal.n against.p @ n.p @"
  }
]
生成json数据jsonGene的代码为:
Java code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="handle.DBlogic"%>
<%@ page import="handle.Seed"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<%
    DBlogic dblogic = new DBlogic();
    ArrayList<Seed> seedList = dblogic.getdata();
    String str = "[";
    int i;
    for(i=0; i<seedList.size()-1; i++){
        Seed seed = seedList.get(i);
        String temp = "{";
        temp += "\"patternTypes\": " + '"' + seed.getPatternTypes() + '"' + ",";
        temp += "\"pattern1\": " + '"' + seed.getPattern1() + '"' + ",";    
        temp += "\"label\": " + '"' + seed.getLabel()+ '"' + ",";
        temp += "\"value\": " + '"' + seed.getValue() + '"' + ",";
        temp += "\"anotherPattern1\": " + '"' + seed.getAnotherPattern1() + '"';
        temp += "},";
        str += temp;
    }
    Seed seed = seedList.get(i);
    String temp = "{";
    temp +=    "\"patternTypes\": " + '"' + seed.getPatternTypes() + '"' + ",";
    temp += "\"pattern1\": " + '"' + seed.getPattern1() + '"' + ",";    
    temp += "\"label\": " + '"' + seed.getLabel()+ '"' + ",";
    temp += "\"value\": " + '"' + seed.getValue() + '"' + ",";
    temp += "\"anotherPattern1\": " + '"' + seed.getAnotherPattern1() + '"';
    temp += "}";
    
    str += temp;
    str += "]";
    
    out.print(str);
 %>
</body>
</html>

 
  相关解决方案