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.02.22 우대락 공연

2025.02.22 우대락 공연 Set List 1. Black Pumas - Colors Covered By 낯선 2. Gate Flowers - 예비역 Covered By 낯선 3. 하동균 - From Mark Covered By 낯선 4. 낯선 ...