How can I create a json file for API calls?
I want to parse all of the returned values from a MySQL database into a JSON file. So I wrote my php side like this:
foreach ($Posts->Show() as $Key => $Post) {
$Data ['POST'][$Post['Post_Id']]["Id"]=$Post['Post_Id'];
$Data ['POST'][$Post['Post_Id']]["Url"] = "https://eastcloud.ir/Blog?=" . $Post['Post_Url'];
$Data ['POST'][$Post['Post_Id']]["Name"] = $Post['Post_Name'];
$Data ['POST'][$Post['Post_Id']]["Date"] = $Post['Post_Date'];
$Data ['POST'][$Post['Post_Id']]["Author"] = $Post['Post_Author'];
$Data ['POST'][$Post['Post_Id']]["Image"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$Data ['POST'][$Post['Post_Id']]["Tags"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$ID++;
}
The given json is something like this:
POST
17
{
Id "17"
Url "https://eastcloud.ir/Blog?=Simplist-Documentations"
Name "Simplist Documentations"
Date "23 May, 2018"
Author "Milad"
Image "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
Tags "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
The loop will continue getting value and parsing them into JSON (The JSON file is available here) but if I want to use the given JSON here on Json2Sharp it tells invalid JSON file given.
What is the solution? How can I create a JSON from my database values with PHP?
php json
add a comment |
I want to parse all of the returned values from a MySQL database into a JSON file. So I wrote my php side like this:
foreach ($Posts->Show() as $Key => $Post) {
$Data ['POST'][$Post['Post_Id']]["Id"]=$Post['Post_Id'];
$Data ['POST'][$Post['Post_Id']]["Url"] = "https://eastcloud.ir/Blog?=" . $Post['Post_Url'];
$Data ['POST'][$Post['Post_Id']]["Name"] = $Post['Post_Name'];
$Data ['POST'][$Post['Post_Id']]["Date"] = $Post['Post_Date'];
$Data ['POST'][$Post['Post_Id']]["Author"] = $Post['Post_Author'];
$Data ['POST'][$Post['Post_Id']]["Image"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$Data ['POST'][$Post['Post_Id']]["Tags"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$ID++;
}
The given json is something like this:
POST
17
{
Id "17"
Url "https://eastcloud.ir/Blog?=Simplist-Documentations"
Name "Simplist Documentations"
Date "23 May, 2018"
Author "Milad"
Image "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
Tags "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
The loop will continue getting value and parsing them into JSON (The JSON file is available here) but if I want to use the given JSON here on Json2Sharp it tells invalid JSON file given.
What is the solution? How can I create a JSON from my database values with PHP?
php json
1
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then:
and key-value pairs except last must end with,
:{"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to usejson_encode($Data)
– Justinas
Nov 13 '18 at 8:48
Something like this:$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
The generated JSON is valid. What is your precise question? Is it about__invalid_type__…
? Then why not mention it?!)
– mario
Nov 13 '18 at 8:51
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56
add a comment |
I want to parse all of the returned values from a MySQL database into a JSON file. So I wrote my php side like this:
foreach ($Posts->Show() as $Key => $Post) {
$Data ['POST'][$Post['Post_Id']]["Id"]=$Post['Post_Id'];
$Data ['POST'][$Post['Post_Id']]["Url"] = "https://eastcloud.ir/Blog?=" . $Post['Post_Url'];
$Data ['POST'][$Post['Post_Id']]["Name"] = $Post['Post_Name'];
$Data ['POST'][$Post['Post_Id']]["Date"] = $Post['Post_Date'];
$Data ['POST'][$Post['Post_Id']]["Author"] = $Post['Post_Author'];
$Data ['POST'][$Post['Post_Id']]["Image"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$Data ['POST'][$Post['Post_Id']]["Tags"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$ID++;
}
The given json is something like this:
POST
17
{
Id "17"
Url "https://eastcloud.ir/Blog?=Simplist-Documentations"
Name "Simplist Documentations"
Date "23 May, 2018"
Author "Milad"
Image "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
Tags "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
The loop will continue getting value and parsing them into JSON (The JSON file is available here) but if I want to use the given JSON here on Json2Sharp it tells invalid JSON file given.
What is the solution? How can I create a JSON from my database values with PHP?
php json
I want to parse all of the returned values from a MySQL database into a JSON file. So I wrote my php side like this:
foreach ($Posts->Show() as $Key => $Post) {
$Data ['POST'][$Post['Post_Id']]["Id"]=$Post['Post_Id'];
$Data ['POST'][$Post['Post_Id']]["Url"] = "https://eastcloud.ir/Blog?=" . $Post['Post_Url'];
$Data ['POST'][$Post['Post_Id']]["Name"] = $Post['Post_Name'];
$Data ['POST'][$Post['Post_Id']]["Date"] = $Post['Post_Date'];
$Data ['POST'][$Post['Post_Id']]["Author"] = $Post['Post_Author'];
$Data ['POST'][$Post['Post_Id']]["Image"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$Data ['POST'][$Post['Post_Id']]["Tags"] = "https://eastcloud.ir/" . $Post['Post_Image'];
$ID++;
}
The given json is something like this:
POST
17
{
Id "17"
Url "https://eastcloud.ir/Blog?=Simplist-Documentations"
Name "Simplist Documentations"
Date "23 May, 2018"
Author "Milad"
Image "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
Tags "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
The loop will continue getting value and parsing them into JSON (The JSON file is available here) but if I want to use the given JSON here on Json2Sharp it tells invalid JSON file given.
What is the solution? How can I create a JSON from my database values with PHP?
php json
php json
edited Nov 13 '18 at 8:45
Justinas
27.1k33559
27.1k33559
asked Nov 13 '18 at 8:43
Milad XandiMilad Xandi
428
428
1
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then:
and key-value pairs except last must end with,
:{"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to usejson_encode($Data)
– Justinas
Nov 13 '18 at 8:48
Something like this:$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
The generated JSON is valid. What is your precise question? Is it about__invalid_type__…
? Then why not mention it?!)
– mario
Nov 13 '18 at 8:51
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56
add a comment |
1
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then:
and key-value pairs except last must end with,
:{"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to usejson_encode($Data)
– Justinas
Nov 13 '18 at 8:48
Something like this:$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
The generated JSON is valid. What is your precise question? Is it about__invalid_type__…
? Then why not mention it?!)
– mario
Nov 13 '18 at 8:51
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56
1
1
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then
:
and key-value pairs except last must end with ,
: {"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to use json_encode($Data)
– Justinas
Nov 13 '18 at 8:48
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then
:
and key-value pairs except last must end with ,
: {"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to use json_encode($Data)
– Justinas
Nov 13 '18 at 8:48
Something like this:
$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
Something like this:
$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
The generated JSON is valid. What is your precise question? Is it about
__invalid_type__…
? Then why not mention it?!)– mario
Nov 13 '18 at 8:51
The generated JSON is valid. What is your precise question? Is it about
__invalid_type__…
? Then why not mention it?!)– mario
Nov 13 '18 at 8:51
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56
add a comment |
3 Answers
3
active
oldest
votes
Did you tried to use json_encode()
method?
foreach ($Posts->Show() as $Key => $Post) {
$Data['POST'] = [
$Post['Post_Id'] = [
"Id" => $Post['Post_Id'],
"Url" => "https://eastcloud.ir/Blog?=" . $Post['Post_Url'],
"Name" => $Post['Post_Name'],
"Date" => $Post['Post_Date'],
"Author" => $Post['Post_Author'],
"Image" => "https://eastcloud.ir/" . $Post['Post_Image'],
"Tags" => "https://eastcloud.ir/" . $Post['Post_Image'],
],
];
$ID++;
}
// here is your json from db fetching loop
$json = json_encode($Data);
upd 1.0
Please check this JSON, which I generated based on your
{
"POST" : [
{
"Id": "17",
"Url": "https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name": "Simplist Documentations",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
},
{
"Id": "18",
"Url": "https://eastcloud.ir/Blog?=angular-2-vs-react",
"Name": "انگیولار ۲ در مقابل ریاکت",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/432644.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/432644.png"
}
]
}
Reponse from json2csharp
public class POST
{
public string Id { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Author { get; set; }
public string Image { get; set; }
public string Tags { get; set; }
}
public class RootObject
{
public List<POST> POST { get; set; }
}
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not leadPost_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
add a comment |
Use the json_encode for creating json. It is not the best way to create it
manually.
To understand what is wrong with your output, the correct JSON format of your data should look like this:
{
"Id":"17",
"Url":"https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name":"Simplist Documentations",
"Date":"23 May, 2018",
"Author":"Milad",
"Image":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
Take a closer look at the quotation marks and the double dots and comma after each not the last line.
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
add a comment |
You can use json_encode() data from database
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276970%2fhow-can-i-create-a-json-file-for-api-calls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Did you tried to use json_encode()
method?
foreach ($Posts->Show() as $Key => $Post) {
$Data['POST'] = [
$Post['Post_Id'] = [
"Id" => $Post['Post_Id'],
"Url" => "https://eastcloud.ir/Blog?=" . $Post['Post_Url'],
"Name" => $Post['Post_Name'],
"Date" => $Post['Post_Date'],
"Author" => $Post['Post_Author'],
"Image" => "https://eastcloud.ir/" . $Post['Post_Image'],
"Tags" => "https://eastcloud.ir/" . $Post['Post_Image'],
],
];
$ID++;
}
// here is your json from db fetching loop
$json = json_encode($Data);
upd 1.0
Please check this JSON, which I generated based on your
{
"POST" : [
{
"Id": "17",
"Url": "https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name": "Simplist Documentations",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
},
{
"Id": "18",
"Url": "https://eastcloud.ir/Blog?=angular-2-vs-react",
"Name": "انگیولار ۲ در مقابل ریاکت",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/432644.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/432644.png"
}
]
}
Reponse from json2csharp
public class POST
{
public string Id { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Author { get; set; }
public string Image { get; set; }
public string Tags { get; set; }
}
public class RootObject
{
public List<POST> POST { get; set; }
}
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not leadPost_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
add a comment |
Did you tried to use json_encode()
method?
foreach ($Posts->Show() as $Key => $Post) {
$Data['POST'] = [
$Post['Post_Id'] = [
"Id" => $Post['Post_Id'],
"Url" => "https://eastcloud.ir/Blog?=" . $Post['Post_Url'],
"Name" => $Post['Post_Name'],
"Date" => $Post['Post_Date'],
"Author" => $Post['Post_Author'],
"Image" => "https://eastcloud.ir/" . $Post['Post_Image'],
"Tags" => "https://eastcloud.ir/" . $Post['Post_Image'],
],
];
$ID++;
}
// here is your json from db fetching loop
$json = json_encode($Data);
upd 1.0
Please check this JSON, which I generated based on your
{
"POST" : [
{
"Id": "17",
"Url": "https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name": "Simplist Documentations",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
},
{
"Id": "18",
"Url": "https://eastcloud.ir/Blog?=angular-2-vs-react",
"Name": "انگیولار ۲ در مقابل ریاکت",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/432644.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/432644.png"
}
]
}
Reponse from json2csharp
public class POST
{
public string Id { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Author { get; set; }
public string Image { get; set; }
public string Tags { get; set; }
}
public class RootObject
{
public List<POST> POST { get; set; }
}
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not leadPost_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
add a comment |
Did you tried to use json_encode()
method?
foreach ($Posts->Show() as $Key => $Post) {
$Data['POST'] = [
$Post['Post_Id'] = [
"Id" => $Post['Post_Id'],
"Url" => "https://eastcloud.ir/Blog?=" . $Post['Post_Url'],
"Name" => $Post['Post_Name'],
"Date" => $Post['Post_Date'],
"Author" => $Post['Post_Author'],
"Image" => "https://eastcloud.ir/" . $Post['Post_Image'],
"Tags" => "https://eastcloud.ir/" . $Post['Post_Image'],
],
];
$ID++;
}
// here is your json from db fetching loop
$json = json_encode($Data);
upd 1.0
Please check this JSON, which I generated based on your
{
"POST" : [
{
"Id": "17",
"Url": "https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name": "Simplist Documentations",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
},
{
"Id": "18",
"Url": "https://eastcloud.ir/Blog?=angular-2-vs-react",
"Name": "انگیولار ۲ در مقابل ریاکت",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/432644.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/432644.png"
}
]
}
Reponse from json2csharp
public class POST
{
public string Id { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Author { get; set; }
public string Image { get; set; }
public string Tags { get; set; }
}
public class RootObject
{
public List<POST> POST { get; set; }
}
Did you tried to use json_encode()
method?
foreach ($Posts->Show() as $Key => $Post) {
$Data['POST'] = [
$Post['Post_Id'] = [
"Id" => $Post['Post_Id'],
"Url" => "https://eastcloud.ir/Blog?=" . $Post['Post_Url'],
"Name" => $Post['Post_Name'],
"Date" => $Post['Post_Date'],
"Author" => $Post['Post_Author'],
"Image" => "https://eastcloud.ir/" . $Post['Post_Image'],
"Tags" => "https://eastcloud.ir/" . $Post['Post_Image'],
],
];
$ID++;
}
// here is your json from db fetching loop
$json = json_encode($Data);
upd 1.0
Please check this JSON, which I generated based on your
{
"POST" : [
{
"Id": "17",
"Url": "https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name": "Simplist Documentations",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
},
{
"Id": "18",
"Url": "https://eastcloud.ir/Blog?=angular-2-vs-react",
"Name": "انگیولار ۲ در مقابل ریاکت",
"Date": "23 May, 2018",
"Author": "Milad",
"Image": "https://eastcloud.ir/Content/Shared/Posts/432644.png",
"Tags": "https://eastcloud.ir/Content/Shared/Posts/432644.png"
}
]
}
Reponse from json2csharp
public class POST
{
public string Id { get; set; }
public string Url { get; set; }
public string Name { get; set; }
public string Date { get; set; }
public string Author { get; set; }
public string Image { get; set; }
public string Tags { get; set; }
}
public class RootObject
{
public List<POST> POST { get; set; }
}
edited Nov 13 '18 at 9:36
answered Nov 13 '18 at 8:57
alexey-novikovalexey-novikov
898
898
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not leadPost_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
add a comment |
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not leadPost_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
Sure. Also, I generated a JSON file here but the JSON is not valid to use on json2sharp
– Milad Xandi
Nov 13 '18 at 9:09
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not lead
Post_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
@MiladXandi Please check my upd 1.0. I've generated some similar array using Laravel and then used it for your tool and seems get a correct response from the json2shart service. Structure is a bit different, there are not lead
Post_ID
and all objects are wrapped in
– alexey-novikov
Nov 13 '18 at 9:38
add a comment |
Use the json_encode for creating json. It is not the best way to create it
manually.
To understand what is wrong with your output, the correct JSON format of your data should look like this:
{
"Id":"17",
"Url":"https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name":"Simplist Documentations",
"Date":"23 May, 2018",
"Author":"Milad",
"Image":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
Take a closer look at the quotation marks and the double dots and comma after each not the last line.
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
add a comment |
Use the json_encode for creating json. It is not the best way to create it
manually.
To understand what is wrong with your output, the correct JSON format of your data should look like this:
{
"Id":"17",
"Url":"https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name":"Simplist Documentations",
"Date":"23 May, 2018",
"Author":"Milad",
"Image":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
Take a closer look at the quotation marks and the double dots and comma after each not the last line.
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
add a comment |
Use the json_encode for creating json. It is not the best way to create it
manually.
To understand what is wrong with your output, the correct JSON format of your data should look like this:
{
"Id":"17",
"Url":"https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name":"Simplist Documentations",
"Date":"23 May, 2018",
"Author":"Milad",
"Image":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
Take a closer look at the quotation marks and the double dots and comma after each not the last line.
Use the json_encode for creating json. It is not the best way to create it
manually.
To understand what is wrong with your output, the correct JSON format of your data should look like this:
{
"Id":"17",
"Url":"https://eastcloud.ir/Blog?=Simplist-Documentations",
"Name":"Simplist Documentations",
"Date":"23 May, 2018",
"Author":"Milad",
"Image":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png",
"Tags":"https://eastcloud.ir/Content/Shared/Posts/SimplistV2.png"
}
Take a closer look at the quotation marks and the double dots and comma after each not the last line.
edited Nov 13 '18 at 8:53
answered Nov 13 '18 at 8:47
DicerosDiceros
13
13
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
add a comment |
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
Even if I send those values directly for encoding, the result is not valid for json2sharp. here is the given result
– Milad Xandi
Nov 13 '18 at 8:54
1
1
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
@MiladXandi Actually it's valid JSON and your json2csharp works fine
– Justinas
Nov 13 '18 at 8:55
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
The output you have given is an array, not a JSON.
– Diceros
Nov 13 '18 at 8:56
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@MiladXandi yep I just used the result from your link on json2csharp and it generates code, no errors. Perhaps it's not the code you wanted, but that's not the same thing as saying it isn't valid. If you're wondering, it creates classes called "invalid type" because you're using numbers as property names in your JSON...you can't make a C# class whose name starts with a number. Perhaps you should tell us what C# you were hoping to generate.
– ADyson
Nov 13 '18 at 9:25
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
@Diceros now I am editing this page to get a valid result
– Milad Xandi
Nov 13 '18 at 10:21
add a comment |
You can use json_encode() data from database
add a comment |
You can use json_encode() data from database
add a comment |
You can use json_encode() data from database
You can use json_encode() data from database
answered Nov 13 '18 at 9:09
TP.ARMTP.ARM
41
41
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276970%2fhow-can-i-create-a-json-file-for-api-calls%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You showed just loop of gathering data, not how you make json. And it's invalid. Keys must be enclosed with double-quote, then
:
and key-value pairs except last must end with,
:{"Id": "17", "Url": "https://eastcloud.ir/Blog?=Simplist-Documentations"}
. Best way is to usejson_encode($Data)
– Justinas
Nov 13 '18 at 8:48
Something like this:
$fp = fopen('Blog.json', 'w'); fwrite($fp, json_encode($Data)); fclose($fp);
– Milad Xandi
Nov 13 '18 at 8:50
The generated JSON is valid. What is your precise question? Is it about
__invalid_type__…
? Then why not mention it?!)– mario
Nov 13 '18 at 8:51
The problem is here when I give this JSON to make its related C# classess.
– Milad Xandi
Nov 13 '18 at 8:56