2015년 11월 27일 금요일

jQuery에서 문자열을 json 객체로 변환시...


parseJSON 을 사용하면 되는 건 맞는데!!! 주의 할 점!!!

문서 대강대강 보다가.. 2시간 날림..!!

문자열 만들때..


1
2
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );

반드시!!! 쌍따옴표를 써야 한다.. javascript여서.. 홑따옴표로 변형해서 썼더니 절대 안됐음..

설명을 잘 읽어 볼걸......

Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all invalid JSON strings:
  • "{test: 1}" (test does not have double quotes around it).
  • "{'test': 1}" ('test' is using single quotes instead of double quotes).
  • "'test'" ('test' is using single quotes instead of double quotes).
  • ".1" (a number must start with a digit; "0.1" would be valid).
  • "undefined" (undefined cannot be represented in a JSON string; null, however, can be).
  • "NaN" (NaN cannot be represented in a JSON string; direct representation of Infinity is also not permitted).

댓글 없음:

댓글 쓰기

[낯선] 2025.10.11 인천 노크 공연

  Live at @인천노크 on 2025.10.11 Set List 1. 디어클라우드 - 얼음요새 Covered by 낯선 2. 낯선 - Misty Dive 3. 솔루션스 - 청춘 Covered by 낯선 4. 낯선 - Not Your Fault...