2013-02-28 3 views
0

작은 문제가 발생했습니다. jQuery $.ajax 호출을 사용하여 JSON 파일에 대한 액세스를 얻으 려하고 온라인에서 두 번 확인했으며 JSON 코드가 유효합니다. 전화를 걸면 JSON의 구문 오류로 구문 분석 오류가 발생합니다.

당신은 여기 http://michael-nolan.com/

를 방문하여 오류를 찾을 수 내 자바 스크립트입니다 : 여기

$(document).ready(function() 
{ 
    $.ajax(
     { type: "GET", 
      url: 'projects/projects.json', 
      dataType: "json", 
     success: function(results) 
     { 
      console.log("Success!"); 
     }, 
     error: function(XMLHttpRequest, textStatus, errorThrown) 
     { 
      console.log(textStatus); console.log(errorThrown); 
     } 
    }); 
}); 

하고하면 오류가와의 문제처럼 소리를 기록하고 내 JSON

{ 
    "projects": 
    [ 
     { 
      "title":"Adobe Suite", 
      "description":"Some stuff", 
      "imgsrc":"img/adobe_suite_description.png" 
     }, 
     { 
      "title":"Gridlock", 
      "description":"Stuff", 
      "imgsrc":"img/gridlock_description.png" 
     }, 
     { 
      "title":"Open Cart", 
      "description":"more stuff", 
      "imgsrc":"img/opencart_description.png" 
     } 
    ] 
} 
+1

Fiddler (http://www.fiddler2.com/fiddler2/)를 사용하여 서버가 원하는 것을 보내고 있는지 확인하십시오. –

+0

오류를 표시 할 수 있습니까? 또한 tmack이 http://jsfiddle.net/을 시도해 보았을 때 복제 할 수 있고 볼 수 있습니다. http://jsfiddle.net/vqagE/ 나를 잘 처리했습니다. 와우, 완전히 다른 유감입니다. 나는 그것을 스스로 점검해야 할 것이다. – John

+0

@ 존 문제가 발생하는 웹 사이트에 대한 링크로 내 질문을 업데이트했습니다. – Nolski

답변

1

오류가 실패 파서가 발생하여 JSON에서 탭과 줄 바꿈이 있습니다

...in the game.</p> 
    <p>Gridlock... 
^ 
| 
the problem 
+0

솔루션에 대한 내 대답보기. '\ t'로 탭을 교체하고'\ n'으로 개행하십시오. –

-1

입니다 너의 아들. json에서 [ ]{}으로 바꾸어보세요.

+0

입니다. 프로젝트는 배열로 간주됩니다. 또한'{} '로 설정하면 JSON 파일이 무효화됩니다. – Nolski

0

나는 귀하의 코드와 그 코드가 작동하는지 테스트 한 결과 나는 귀하의 사이트에서 시도한 결과 304 not modified라고 알려주었습니다.

따라서 getJson() jQuery 메서드를 사용해보십시오.

$.getJSON('projects/projects.json', function(data) { 

}); 
+0

'$ .getJSON()'을 사용할 때 콜백을 실행하는 것처럼 보이지 않습니다. 피들러를 볼 때 여전히 여전히 304 – Nolski

0

테스트했을 때 코드가 올바르게 작동했습니다. 구문 오류가 무엇인지에 따라 json이 어떻게 생성되는지 확인하고 projects/projects.json으로 이동하면 json이 올바르게 생성되는지 확인할 수 있습니다. json이 생성되면 정적 JSON으로 바꾸고 작동하는지 확인하십시오.

2

Chrome에서 잘 작동합니다. IE는 특히 JSON (모든 것)에 엄격하게 적용됩니다.

두 번째 및 세 번째 설명에서 개행을 찾으십시오. 그게 IE에서 실패한 것 같아.

+0

을 던지고 있습니다. 이것은 분명히 문제를 일으켰습니다. 감사! – Nolski

0

두 번째 배열 항목에 두 단락 사이의 공백 (아마도 줄 바꿈 문자) 함께 할 수있는 뭔가가 . 예를 들어 \n\t와 줄 바꿈으로 각 탭 인스턴스를 교체 :

예 JSON 파일 :

{ 
    textWithTabs : "This is text with \t a tab and \n newline" 
} 

자바 스크립트 :

var o = JSON.parse(json); 

console.log(o.textWithTabs); //This is text with  a tab and ↵ newline 
0

내가 이것을 시도 할 제안 :

{ 
"projects": [ 
    { 
     "title": "Adobe Suite", 
     "description": "<p>With years of experience using the Adobe Suite products I have skills that range from creating vector artwork in Adobe Illustrator, arranging web layouts in Adobe Photoshop, and creating print layouts in Adobe InDesign</p>", 
     "imgsrc": "img/adobe_suite_description.png" 
    }, 
    { 
     "title": "Gridlock", 
     "description": "<p>In my Sophomore year in college I worked with Jayson Fitch as an artist on a isometric 2d shooter called Gridlock. We as a team created all of the art assets that are being used in the game.</p><p> Gridlock is still in development and we hope to release it on the OUYA.Check out it's development blog here. <a href='http://gridlock-game.tumblr.com'>www.Gridlock-Game.Tumblr.com</a></p>", 
     "imgsrc": "img/gridlock_description.png" 
    }, 
    { 
     "title": "Open Cart", 
     "description": "<p>As a freelance project I initiated an overhaul of the Legendary Realms Terrain e-commerce storefront. This entailed a complete visual re-branding as well as creating a backend solution to expand online payment options.</p><p> Feel free to check them out at < a href = 'lrterrain.com' > Legendary Realms Terrain < /a></p > ", 
     "imgsrc": "img/opencart_description.png" 
    } 
    ] 
} 
관련 문제