こんにちは私は問題があり、同様のことを試みましたが、答えましたがObject.keys(data).lengthはどちらも役に立ちません。ここに私のJSONはJSONの長さが配列の要素の数ではなく文字の数を返します
{
"POSTS": [
[
{
"term_id": 1,
"name": "Uncategorized",
"slug": "uncategorized",
"term_group": 0,
"term_taxonomy_id": 1,
"taxonomy": "category",
"description": "",
"parent": 0,
"count": 1,
"filter": "raw",
"cat_ID": 1,
"category_count": 1,
"category_description": "",
"cat_name": "Uncategorized",
"category_nicename": "uncategorized",
"category_parent": 0
},
{
"term_id": 2,
"name": "Nova",
"slug": "nova",
"term_group": 0,
"term_taxonomy_id": 2,
"taxonomy": "category",
"description": "",
"parent": 0,
"count": 1,
"filter": "raw",
"cat_ID": 2,
"category_count": 1,
"category_description": "",
"cat_name": "Nova",
"category_nicename": "nova",
"category_parent": 0
},
{
"term_id": 3,
"name": "nova1",
"slug": "nova1",
"term_group": 0,
"term_taxonomy_id": 3,
"taxonomy": "category",
"description": "",
"parent": 0,
"count": 1,
"filter": "raw",
"cat_ID": 3,
"category_count": 1,
"category_description": "",
"cat_name": "nova1",
"category_nicename": "nova1",
"category_parent": 0
},
{
"term_id": 4,
"name": "nova2",
"slug": "nova2",
"term_group": 0,
"term_taxonomy_id": 4,
"taxonomy": "category",
"description": "",
"parent": 3,
"count": 1,
"filter": "raw",
"cat_ID": 4,
"category_count": 1,
"category_description": "",
"cat_name": "nova2",
"category_nicename": "nova2",
"category_parent": 3
},
{
"term_id": 5,
"name": "nova3",
"slug": "nova3",
"term_group": 0,
"term_taxonomy_id": 5,
"taxonomy": "category",
"description": "",
"parent": 3,
"count": 1,
"filter": "raw",
"cat_ID": 5,
"category_count": 1,
"category_description": "",
"cat_name": "nova3",
"category_nicename": "nova3",
"category_parent": 3
}
]
],
"success": 1
}
されており、ここに私のjavascriptのコードは次のとおりです。
<select id ="new" name="new"></select>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
var select = document.getElementById("new");
$.ajax({
type: "POST",
url: "wp-content/themes/twentyfourteen/ajax.php", // this script returns my JSON
data: ({canum: 0}),
success: function(data){
console.log(Object.keys(data).length);
}
});
});
</script>
私は必要なので、これは代わりに5を取得する方法をJSON
内のセグメントの数を取得する方法を、長さがない5として私に1445を返します。文字数の?
お願いします。ありがとうございました。
あなたのjsonは解析するまで文字列になるでしょうか? http://api.jquery.com/jquery.parsejson/ – Nick